- All unit test files should be placed under /__tests__
- Every test file's name should be suffixed with .spec.js
Every test should convey the following information
- Unit of work which is being tested
- Scenario in which the unit is being tested
- Expected Behaviour of the unit in a given scenario
Considering the above design goals - when testing a module the test codebase should be structured using the following mocha test helpers.
- to be used to wrap all the test cases related to a Unit of work or wrap multiple suite()'s.
- The message should be of the format "<helperFunction/filename> Test Cases:".
- all the mock data variables should be declared here
- to be used to convey the the scenario for which the Unit of work is being tested or wrap multiple describe()'s.
- a describe should only hold one scenario, if tests are written for combination of scenarios then nested describe() should be used.
- outermost wrapper describe's message should be of the format When .
- inner wrapper describe's message should be of the format and when .
- the arguments to be passed to the unit of work should be declared and assigned with one of the values from the mock data declared at suite()
- to be used to convey the expected behaviour in a particular scenario of the unit of work
- the message should be of the format should
- only one assert() should be used per it() test (if first assert fails other asserts are not tested)
- actualResult variable needs to be declared within it() and needs to be passed as the first argument