Jest
Tool for running tests over Javascript/Typecript
Installing
For TypeScript install Jest with ts-jest preprocessor with:
Because we are running with ts-jest create the jest.config.js file, which will inform Jest how to handle .ts files correctly.
Test files for Jest are named <file>.test.ts.
By specific filename
Specific filename AND path
Run only the tests that were specified with their exact paths.
Specific filename
Find and run the tests that cover a space separated list of source files.
It will regex only by the specified name, so if multiple files have the same name it will execute all of them.
With coverage
On watch mode
Watch files for changes and rerun tests.
To rerun only changed files
To rerun all files
Creating tests
Create a test by using the test() funtion or its alias it().
Using describe()
describe()Create a block that groups together several related tests.
This isn't required - you can write the test blocks directly at the top level. But this can be handy if you prefer your tests to be organized into groups.
You can also nest describe blocks if you have a hierarchy of tests.
You define multiple values for a specific test instead of creating multiple test functions with different values.
The .each modifier offers few different ways to define a table of the test cases.
Run specific test
To run only specific test or block of tests use:
Skip tests
To skip tests or block of tests, just append skip modifier right after test | it | describe.
Use the .concurrent modifier to run test concurrently.
You can't use this modifier in describe() blocks.
Is experimental, as for version 29.
Last updated
