Registry / testing / jest-test-matrix

jest-test-matrix

JSON →
library1.2.0jsnpmunverified

jest-test-matrix is a utility for Jest that streamlines the process of testing functions across all possible combinations of input parameters. Instead of manually writing individual test cases for each scenario, it enables developers to define a matrix of inputs, and the utility automatically generates and executes tests for every permutation. The current stable version is 1.2.0, and as a specialized testing utility, it typically sees infrequent but stable updates. This package is particularly useful for verifying the behavior of functions with multiple arguments where comprehensive combinatorial testing is desired, significantly reducing boilerplate code. It integrates directly with Jest's snapshot testing, producing a well-formatted, tabular snapshot that clearly displays inputs and corresponding outputs for each tested combination, aiding in quick visual verification and regression detection. This approach simplifies test maintenance and ensures thorough coverage for complex input scenarios.

npm install jest-test-matrix
INSTALL
IMPORT
SIG · JEST-TEST-MATRIX
J
jest-test-matrix
testingjavascriptv1.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

testMatrix
import testMatrix from 'jest-test-matrix';
import { testMatrix } from 'jest-test-matrix';
The primary utility function `testMatrix` is exported as a default export.
testMatrix (CommonJS)
const testMatrix = require('jest-test-matrix');
For CommonJS environments, `require` is used to import the default export.

This example demonstrates how to use `testMatrix` to generate all combinations for `amount`, `balance`, and `status` parameters and verify the output using Jest's snapshot testing.

import testMatrix from 'jest-test-matrix'; interface CanPayOpts { amount: number; balance: number; status: 'active' | 'locked' | 'expired'; } function canPay({amount, balance, status}: CanPayOpts){ if (status === 'locked' || status == 'expired'){ return false; } return balance > amount; } describe('Payment eligibility', () => { it('should only allow valid payments based on various conditions', () => { expect( testMatrix(canPay, { amount: [20, 100], balance : [50], status: ['active', 'locked', 'expired'] }) ).toMatchSnapshot(); }); });
Debug
Known issues
gotchaThe `testMatrix` function expects the tested function to accept a single object as its argument. If your function takes multiple discrete arguments (e.g., `fn(a, b)`), you must wrap it in an anonymous function that adapts the input structure (e.g., `({a, b}) => fn(a, b)`).
fix
Wrap your function call inside an anonymous function that destructures the input object, like `testMatrix(({arg1, arg2}) => myFunction(arg1, arg2), { arg1: [...], arg2: [...] })`.
affects: >=1.0.0
gotchaGenerated snapshots can become very large and difficult to review or diff if the tested function has many parameters or many possible values for each parameter. While formatted as a table, extensive matrices still require careful attention.
fix
Keep the number of input combinations manageable for critical functions. Consider splitting complex tests into smaller matrices, or use more targeted assertions if the generated snapshot is too verbose.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0 , _jestTestMatrix.default) is not a function
`testMatrix` is a default export, but it's being imported as a named export.
fix
Change the import statement to `import testMatrix from 'jest-test-matrix';`.
Snapshot mismatch
The generated output from `testMatrix` for your function and inputs has changed, and the current snapshot no longer matches. This could be due to a change in the function's logic, a change in the input values provided to `testMatrix`, or an uncommitted snapshot.
fix
Review the proposed snapshot changes in your terminal output. If the change is intentional, update the snapshot by running Jest with the `--updateSnapshot` or `-u` flag (`jest -u`). If unintentional, debug your function or input parameters.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
jestrequiredThis package is a Jest plugin and requires Jest to be installed as a peer dependency for test execution.
Agent activity
4 hits · last 30 days
node
4
Resources
jest-test-matrix — npm install jest-test-matrix · libregistry