Installations
npm install jest-test-each
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
14.18.1
NPM Version
7.0.14
Score
77.9
Supply Chain
98.7
Quality
76
Maintenance
100
Vulnerability
100
License
Contributors
Unable to fetch Contributors
Languages
TypeScript (99.39%)
JavaScript (0.61%)
Developer
mmisty
Download Statistics
Total Downloads
46,834
Last Day
28
Last Week
291
Last Month
10,550
Last Year
35,539
GitHub Statistics
3 Stars
143 Commits
1 Watching
5 Branches
1 Contributors
Bundle Size
11.61 kB
Minified
3.98 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.9.1
Package Id
jest-test-each@0.9.1
Unpacked Size
176.04 kB
Size
23.18 kB
File Count
64
NPM Version
7.0.14
Node Version
14.18.1
Total Downloads
Cumulative downloads
Total Downloads
46,834
Last day
-93.8%
28
Compared to previous day
Last week
-90.6%
291
Compared to previous week
Last month
-19.9%
10,550
Compared to previous month
Last year
589.4%
35,539
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
jest-test-each
This package will help you to run parametrised tests easily [typesafe] without text tables or arrays of arrays.
Table of Contents
Examples
You can see demo project here.
Tests are here.
Simple
1its('roundings') 2 .each([ 3 { input: 0, expected: '0' }, 4 { input: 0.99, expected: '1' }, 5 { input: 102.99998, expected: '103' }, 6 { input: -6, expected: '-6' }, 7 ]) 8 .run(t => { 9 expect(Math.round(t.input).toFixed(0)).toBe(t.expected); 10 });
Run test in idea with jest plugin:
More complex
1its('check calculator') 2 .each([ 3 { a: 1, b: 2, exp: [3, -1, 2, 0.5] }, 4 { a: 1, b: 0, exp: [1, 1, 0, Infinity] }, 5 ]) 6 .each(t => [ 7 { sign: '+' as const, exp: t.exp[0] }, 8 { sign: '-' as const, exp: t.exp[1] }, 9 { sign: '*' as const, exp: t.exp[2] }, 10 { sign: '/' as const, exp: t.exp[3] }, 11 ]) 12 .each(t => [{ flatDesc: `${t.a} ${t.sign} ${t.b} should be ${t.exp}` }]) 13 .run(async t => { 14 expect(calc(t.a, t.b, t.sign)).toBe(t.exp); 15 });
and the same test with auto cases names:
Setup
Install dev dependency:
yarn add -D jest-test-each
To setup jest you need to have jest.config.js config (official details)
In your jest.config.js config add:
1// jest.config.js 2module.exports = { 3 ... 4 setupFilesAfterEnv: ["./config/setup.js"], 5 ... 6};
In './config/setup.js' file add the following (this is required for global vars to be available):
require('jest-test-each');
for .ts tests to see globals 'its' and 'Test' add the following to your tsconfig:
// tsconfig.json
"include": [
...
"node_modules/jest-test-each/dist/index.d.ts"
]
Additional [optional]
You can override test runner environment (by default it is jest env) by the following:
1TestEachEnv({ 2 describe: describe, 3 it: it, 4 beforeAll: beforeAll, 5 ... 6});
Features
- cases multiplication (
.each().each()....run()
) - ability to setup test-each (global setup or each test setup):
- number suites/cases or not
- group each level by suite or not
- concurrent testing
- max length of case name - on reaching it will ask to sepcify explicit description for case
- ability to setup test runner environment (by default it is jest)
- ability to specify description for each case as function depending on case args
- ability to create .each level depending on previous data
- ability to have flat tests cases (not groupped to suites) when each case has 'flatDesc'
- global var 'Test' (or 'its' alias) to access test each (I'm accepting suggestions on namings)
- ability to run without single .each (
its('foo').run(..)
) - To run one test from TestEach like it.only (
.only(<filter>)
) (example). - ability to run '.before' in testEach with disposable interface for automatic cleanup (example).
- ability to skip test if it is marked with defect (example).
- added field 'actualFailReasonParts' for case - to fail when defected test fails with other reason than expected (example).
- '.ensure' to check cases match some condition (example).
- '.ensureCasesLength' to check cases length - in case when .each has dynamic args and you don't want to miss some tests (example).
- ability to skip test
- do not create suite wrapping when resulted to only one test in the group
.only() usage
See example.
Running the feature containing this will result in 2 tests
1 its('Simple test: roundings') 2 .each([ 3 { input: 0, expected: '0' }, 4 { input: 0.99, expected: '1' }, 5 { input: 102.99998, expected: '103' }, 6 { input: -6, expected: '-6' }, 7 ]) 8 .only(t => t.input === -6) 9 .run(t => { 10 expect(Math.round(t.input).toFixed(0)).toBe(t.expected); 11 });
What's next
- todo
Unavailable features
- to start testEach by Idea plugin (workaround: wrap with describe and do not put name into Test Each)
Releases
0.9.0
Supporting jest 27.
Working with Skip and Defect:
- When using test-runner 'jest-circus' (default runner in jest 27):
- defected tests which fail will not be marked skipped as it was before, it will be marked as passed.
- defected tests which passed will fail as before
- skipping test will not run test but it will be marked as passed
- When using test runner 'jest-jasmine2' everything will be as before.
You can add the following in jest.config.js to use 'jest-jasmine2' runner:
1 test-runner: "jest-jasmine2"
0.8.8
- Ability to add flatDesc to cases simplier - as function for each (.each(..).desc(t=>...))
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 1 are checked with a SAST tool
Reason
15 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
1.3
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to jest-test-each
jest-each
Parameterised tests for Jest
eslint-plugin-jest-test-each-formatting
ESLint rules for formatting jest test.each
jest-plugin-for-each
Jest plugin to test multiple values for a single outcome.
@knapsack-pro/jest
Knapsack Pro Jest splits Jest tests across CI nodes and makes sure that tests will run in optimal time on each CI node.