Jest testing useful commands

Here are some commands useful with the lovely jest.

The setup, enable the jest command in the console:

npm install -g jest-cli

Run a single test with detailed output:

jest <path to the test>/<test name>.spec.js --verbose

Run tests without cache:

jest --nocache

Run tests matching a certain name and show detailed output:

jest -t '<name of the test, as specified in its definition>' --verbose

Important note: done need be used as a parameter, only of async is needed inside the test. If used, do remember to call done() at the end of the function or wherever it is needed.

Documentation:

  • https://facebook.github.io/jest/docs/en/cli.html

Sources:

  • https://stackoverflow.com/questions/42827054/how-do-i-run-a-single-test-using-jest
  • https://stackoverflow.com/questions/46169824/intercept-navigation-change-with-jest-js-or-how-to-override-and-restore-locatio
  • http://facebook.github.io/jest/docs/en/jest-object.html#jestspyonobject-methodname
  • https://stackoverflow.com/questions/4144686/how-to-write-a-test-which-expects-an-error-to-be-thrown-in-jasmine