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-matrixVerified import paths — ran on the pinned version, not inferred.
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.
Wrap your function call inside an anonymous function that destructures the input object, like `testMatrix(({arg1, arg2}) => myFunction(arg1, arg2), { arg1: [...], arg2: [...] })`.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.
Change the import statement to `import testMatrix from 'jest-test-matrix';`.
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.