Running the tests

To run the tests, open a terminal instance in the /chapter-09-node/testing-example folder and run the following command:

npm test

You should see the following output in your terminal:

main.wasm Tests
the _addTwoNumbers function
✓ returns 300 when 100 and 200 are passed in (4ms)
✓ returns -20 when -10 and -10 are passed in
the _divideTwoNumbers function
✓ returns 10 when 100 and 10 are passed in
✓ returns -2 when -10 and 5 are passed in (1ms)
✓ returns ~3.77 when 20.75 and 5.5 are passed in
the _findFactorial function
✓ returns 120 when 5 is passed in (1ms)
✓ returns 362880 when 9.2 is passed in

Test Suites: 1 passed, 1 total
Tests: 7 passed, 7 total
Snapshots: 0 total
Time: 1.008s
Ran all test suites.

If you have a large number of tests, you could remove the --verbose flag from the test script in package.json and only pass the flag to the npm test command if needed. There are several other CLI flags you can pass to the jest command. The following list contains some of the more commonly used flags:

  • --bail: Exits the test suite immediately upon the first failing test suite
  • --coverage: Collects test coverage and displays it in the terminal after the tests have run
  • --watch: Watches files for changes and reruns tests related to changed files

You can pass these flags to the npm test command by adding them after a --. For example, if you wanted to use the --bail flag, you'd run this command:

npm test -- --bail

You can view the entire list of CLI options on the official site at https://jestjs.io/docs/en/cli.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset