React.js 12: Testing: Mocha Chai

Docs

https://mochajs.org/

https://www.chaijs.com/


Problem Statement

We want a reliable way to test our code, not just once, but automatically and often/continuously as our project grows.

A unit test is designed to test the smallest unit of your code, like a single function.

Solution

Mocha: a test runner. A test runner is a command line tool for executing test files and displaying the results.

Chai: assertion library for node and the browser.

Sinon: test library supporting stubs, spies and mocks.

https://stackshare.io/stackups/chai-vs-mocha


Test-Driven Development - aka TDD

In TDD, test are written first and the test has to fail. Then The code is written to make the test pass.

TDD requires you to:

  • Write tests for the required software functionality

  • Run the tests for the software functionality

  • Implement the software functionality

  • Fix bugs and refactor until all tests pass

  • Repeat the cycle for any new functionality


Behavior-Driven Development - aka BDD

Behavior-driven development (BDD) aims to help developers build software that is predictable, resilient to changes, and not error-prone. It evolved from test-driven development (TDD).

The main difference between TDD and BDD is that BDD calls for writing test cases in a shared language to simplify communication between technical and nontechnical stakeholders, such as developers, QA teams, and business leaders.

Another difference is that in TDD, test are written first and the test has to fail. Then The code is written to make the test pass.


Last updated