jest-each
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@jest/types | 29.6.3 | 8 kB | MIT | prod | |
chalk | 4.1.2 | 11.31 kB | MIT | prod | |
jest-get-type | 29.6.3 | 1.72 kB | MIT | prod | |
jest-util | 29.7.0 | 10.86 kB | MIT | prod | |
pretty-format | 29.7.0 | 14.34 kB | MIT | prod |
Jest-each is a parameterised testing tool for JavaScript testing framework Jest. Its main function is to allow multiple arguments to be passed into your test or describe functions, resulting in each test or suite being run once per row of parameters. This enables efficient and comprehensive testing across multiple sets of data. The Jest-each library is inspired by the mocha-each library, however it is specifically designed for use with Jest.
To use jest-each in your JavaScript testing suite, you'll first need to install it. This can be done via npm (Node Package Manager) with the command npm i --save-dev jest-each
, or via yarn with yarn add -D jest-each
. Once installed, you can import it into your test files. In ES6 syntax, you can import it with import each from 'jest-each';
, or if you're using ES5, const each = require('jest-each').default;
.
Jest-each can be used in a variety of contexts within your Jest tests. For example, to use it within a test, you can pass an array of arrays containing parameters into the each function, followed by the test function itself. Here's a simple use case:
each([
[1, 1, 2],
[1, 2, 3],
[2, 1, 3],
]).test('returns the result of adding %d to %d', (a, b, expected) => {
expect(a + b).toBe(expected);
});
In the above example, %d
are placeholders for each parameter in the array, and each array of parameters is run as a separate test.
Jest-each can also be used in much the same way for asynchronous tests or describe blocks.
The jest-each docs can be found on the Jest GitHub page at https://github.com/jestjs/jest. Further details about its usage and capabilities can be found there. To stay fully abreast of updates and changes to jest-each, it's recommended to keep an eye on this repository.