Jest: Data-driven test support through a "where" block

Created on 9 May 2018  路  3Comments  路  Source: facebook/jest

馃殌 Feature Proposal

The ability to provide data sets which are fed into a single test.
Those test executions are then considered unique independent tests.

Motivation

This makes it possible to write smaller tests that cover a broader range of cases.
Such a feature is available in Spock, a Groovy-based test framework.

Example

Re-using the examples from Spock above (obviously with a more limited syntax), it could look something like this:

it('maximum of #a and #b is #c', d => {
    expect(Math.max(d.a, d.b)).toBe(d.c);
}, [
    {a: 3, b: 5, c: 5},
    {a: 7, b: 0, c: 7},
    {a: 0, b: 0, c: 0}
]);

Pitch

I believe this is a core feature as it impacts the test execution, how tests are named, etc.

Most helpful comment

Data-driven tests will be a part of Jest 23, see https://github.com/facebook/jest/pull/6102

All 3 comments

Data-driven tests will be a part of Jest 23, see https://github.com/facebook/jest/pull/6102

@thymikee just beat me to it!

@rraziel In the meantime jest-each offers the same API being released in Jest 23

Hm getting a requested feature the way I wanted it, before I even submitted the request... not going to complain 馃憤

Was this page helpful?
0 / 5 - 0 ratings