jest
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@babel/core | 7.24.4 | 763.3 kB | MIT | prod peer | 1 1 |
@jest/core | 29.7.0 | 30.03 kB | MIT | prod | 1 1 |
@jest/transform | 29.7.0 | 12.12 kB | MIT | prod | 1 1 |
@jest/types | 29.6.3 | 8 kB | MIT | prod | |
@types/babel__core | 7.20.5 | 9.48 kB | MIT | prod | |
babel-plugin-istanbul | 6.1.1 | 7.65 kB | BSD-3-Clause | prod | 1 1 |
babel-preset-jest | 29.6.3 | 1.53 kB | MIT | prod | 1 1 |
chalk | 4.1.2 | 11.31 kB | MIT | prod | |
exit | 0.1.2 | 14.94 kB | MIT | prod | |
graceful-fs | 4.2.11 | 9.57 kB | ISC | prod | |
import-local | 3.1.0 | 2.34 kB | MIT | prod | |
jest-cli | 29.7.0 | 9.85 kB | MIT | prod | 1 1 |
jest-config | 29.7.0 | 25.91 kB | MIT | prod | 1 1 |
jest-util | 29.7.0 | 10.86 kB | MIT | prod | |
prompts | 2.4.2 | 31.91 kB | MIT | prod | |
slash | 3.0.0 | 1.8 kB | MIT | prod |
Jest is a delightful JavaScript Testing solution. As a developer-ready package, it provides a complete and easy to set-up JavaScript testing solution that works out of the box for any React project. Awesome features of Jest include instant feedback where failed tests run first. Its fast interactive mode can switch between running all tests or only test files related to changed files. More so, Jest has a snapshot testing feature that can capture snapshots of React trees or other serializable values to simplify UI testing.
Using Jest is straightforward. After installing it in your project, you can use it to create tests in a separate test file or even inline using jest.fn()
and expect statements. Here is a simple example:
const sum = require('./sum');
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
In this example, we only have one test that imports a function from a module and checks if it performs the expected operation. If you have the setup to use Babel, you can even use ES6 imports.
To run your tests, you'll use the Jest command line interface, usually through npm scripts, like so:
"scripts": {
"test": "jest"
},
Then in the terminal, you can just run npm test
and Jest will run your tests. Jest will automatically find test files that end with .spec.js
(or .test.js
) in the entire project.
For comprehensive details about Jest and its usage, the documentation is provided on the Jest official website. You can access it at https://jestjs.io/. The docs provide a thorough guide on getting started with Jest, API references, configurational guides and much more. The snapshot testing feature of Jest can be found here.