You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP

jest-each

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
j

jest-each

Parameterised tests for Jest

30.0.2
100

Supply Chain Security

100

Vulnerability

100

Quality

96

Maintenance

100

License

Version published
Weekly downloads
34M
-4.93%
Maintainers
6
Weekly downloads
 
Created
Issues
277

What is jest-each?

The jest-each npm package is an extension for Jest, a popular JavaScript testing framework. It allows you to run a single test multiple times with different sets of data, making it easier to test functions with various inputs and expected outputs.

What are jest-each's main functionalities?

Parameterized Tests

This feature allows you to run the same test with different sets of data. In this example, the test checks if the sum of two numbers equals the expected result for multiple sets of inputs.

const each = require('jest-each').default;

each([ [1, 1, 2], [1, 2, 3], [2, 1, 3] ]).test('adds %d and %d to equal %d', (a, b, expected) => {
  expect(a + b).toBe(expected);
});

Table-Driven Tests

This feature allows you to define test cases in a tabular format, making it easier to read and manage multiple test cases. The example demonstrates how to use a table to test the addition of two numbers.

const each = require('jest-each').default;

each`
  a    | b    | expected
  ${1} | ${1} | ${2}
  ${1} | ${2} | ${3}
  ${2} | ${1} | ${3}
`.test('adds $a and $b to equal $expected', ({ a, b, expected }) => {
  expect(a + b).toBe(expected);
});

Other packages similar to jest-each

FAQs

Package last updated on 19 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts