Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jest-each

Package Overview
Dependencies
Maintainers
6
Versions
144
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-each

Parameterised tests for Jest

  • 28.0.0-alpha.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.7M
decreased by-80.12%
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

FAQs

Package last updated on 10 Feb 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc