Skip to content

cameronhunter/jest-plugin-datapoints

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jest-datapoints-plugin

This is a Jest plugin which adds a datapoints method to test and it. Its use is to provide a combinatorial test suite from user-provided data points. This, mixed with snapshots, provides high levels of coverage of the function under test at the cost of human verification of the results.

Example:

const suite = test.datapoints({
  a: [true, false],
  b: [true, false]
});

suite(({ a, b }) => {
  expect(a && b).toMatchSnapshot();
});

// Test suites can also have titles which use the `$<field>` syntax to use
// data point values in the name.
suite('a: $a, b: $b', ({ a, b }) => {
  expect(a && b).toMatchSnapshot();
});

The above example will create four test cases (the cartesian product of the datapoints) and the resulting snapshot will look something like:

exports[`snapshot {"a":false,"b":false} 1`] = `false`;

exports[`snapshot {"a":false,"b":true} 1`] = `false`;

exports[`snapshot {"a":true,"b":false} 1`] = `false`;

exports[`snapshot {"a":true,"b":true} 1`] = `true`;

Installation

$ yarn add --dev jest-plugin-datapoints

Add the plugin to your Jest configuration:

{
  "setupFilesAfterEnv": ["jest-plugin-datapoints"]
}

If you're using TypeScript, you can add jest-plugin-datapoints/types.d.ts to your types field in tsconfig.json. The values injected in the test case will be fully typed from the inputs provided to the datapoints function.

About

Create Jest test cases from the cartesian product of data points

Resources

Stars

Watchers

Forks

Packages

No packages published