Testing done with Jest
This folder holds all the unit tests that run on the field validation scripts. The directory structure reflects that of the validationFunctions folder.
Testing files end with .test.js
- Import the validation function you want to test with a 'require' statment.
- Use a
describe
block to logically categorize your tests. Ref. - Write
test
blocks withindescribe
blocks. Ref. - Call different variations of arguments to the validation function and run the output through an
expect
function. Ref.
Hints
Alternatively, you can use an array of arrays containing testing inputs and expected outputs, and take advantage of
test.each()
to avoid writing multiple test blocks. Ref.
You can use
.only
or.skip
ondescribe
ortest
blocks to control which subset of tests you want to run.
npx jest <test file name>
npx jest <testname1> <testname2> <testname3>
npm run test
or npx jest
npx jest --collectCoverage