New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jest-each

Package Overview
Dependencies
Maintainers
6
Versions
145
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-each

Parameterised tests for Jest

29.7.0
latest
Source
npm
Version published
Weekly downloads
27M
2.73%
Maintainers
6
Weekly downloads
 
Created

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

Keywords

jest

FAQs

Package last updated on 12 Sep 2023

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