jest-plugin-datapoints
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i jest-plugin-datapoints

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

5.87 kB

Total Files

11

Last publish

Collaborators

  • cameronhunter