Registry / testing / jest-in-case

jest-in-case

JSON →
library1.0.2jsnpmunverified

jest-in-case is a utility for the Jest testing framework that simplifies the creation of parameterized tests. It allows developers to define a single test function (`tester`) and supply multiple sets of input data (`testCases`) as either an array of objects or an object whose keys serve as test names. This dramatically reduces boilerplate when testing a function or component with numerous input variations. The package helps organize tests by automatically generating named test cases using Jest's `test` function, and supports `test.only` and `test.skip` via special `only` and `skip` properties within test cases. The latest version, 1.0.2, was published on September 8, 2017, making it an effectively abandoned project. This means it has not been updated in over nine years and is likely incompatible with recent major versions of Jest (e.g., Jest 30) and modern Node.js environments. There is no active release cadence, and it lacks contemporary features like native TypeScript support.

npm install jest-in-case
INSTALL
IMPORT
SIG · JEST-IN-CASE
J
jest-in-case
testingjavascriptv1.0.2
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.

cases
import cases from 'jest-in-case';
import { cases } from 'jest-in-case';
The 'cases' function is the default export. Using named import syntax will result in an error in ESM contexts.
cases
const cases = require('jest-in-case');
const { cases } = require('jest-in-case');
For CommonJS environments, 'cases' is the module.exports value. Destructuring will fail.

This quickstart demonstrates how to use `jest-in-case` with both array and object-based test cases, including an asynchronous test example, to run multiple variations of the same test against `add` and `subtract` functions.

/* file: math.js */ export function add(augend, addend) { return augend + addend; } export function subtract(minuend, subtrahend) { return minuend - subtrahend; } /* file: math.test.js */ import cases from 'jest-in-case'; import { add, subtract } from './math'; describe('Math operations', () => { cases('add(augend, addend) should return correct total', opts => { expect(add(opts.augend, opts.addend)).toBe(opts.total); }, [ { name: '1 + 1 = 2', augend: 1, addend: 1, total: 2 }, { name: '2 + 1 = 3', augend: 2, addend: 1, total: 3 }, { name: '3 + 1 = 4', augend: 3, addend: 1, total: 4 }, ]); cases('subtract(minuend, subtrahend) should return correct difference', opts => { expect(subtract(opts.minuend, opts.subtrahend)).toBe(opts.difference); }, { '5 - 2 = 3': { minuend: 5, subtrahend: 2, difference: 3 }, '10 - 7 = 3': { minuend: 10, subtrahend: 7, difference: 3 } }); cases('async test example', async ({ input, expected }) => { const result = await Promise.resolve(input * 2); expect(result).toBe(expected); }, [ { name: 'doubles 5 to 10', input: 5, expected: 10 }, { name: 'doubles 10 to 20', input: 10, expected: 20 } ]); });
Debug
Known issues
breakingThis package is effectively abandoned, with its last release (1.0.2) in September 2017. It is highly unlikely to be compatible with modern versions of Jest (e.g., Jest 30), Node.js, or contemporary module systems (ESM). Using it may lead to critical failures or unexpected behavior in newer environments.
fix
Consider migrating to native Jest parameterized testing (`test.each`) or other actively maintained alternatives like `jest-when` for modern Jest setups.
affects: >=1.0.3 (hypothetical), or any version with modern Jest/Node.js
gotchaThe `name`, `only`, and `skip` properties are reserved keywords within test case objects passed to `jest-in-case`. If you include these properties with custom values, they will be overridden or used by `jest-in-case` for test naming and conditional execution, potentially leading to unexpected test behavior or data loss.
fix
Avoid using `name`, `only`, or `skip` as keys for your test data within the test case objects. Choose alternative property names for your test parameters.
affects: >=1.0.0
gotchaDue to its age, `jest-in-case` does not ship with TypeScript type definitions, nor does it officially support TypeScript. While it might be used in a TypeScript project with `@ts-ignore` or manually created declaration files, this is not officially supported and can lead to type safety issues.
fix
For TypeScript projects, it's strongly recommended to use Jest's built-in `test.each` feature or other modern alternatives that provide native TypeScript support for parameterized tests.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: cases is not a function
Attempting to use `jest-in-case` with incorrect import syntax (e.g., named import for a default export) or in an environment where module resolution fails due to its age.
fix
Ensure `cases` is imported as a default export: `import cases from 'jest-in-case';` for ESM or `const cases = require('jest-in-case');` for CommonJS. Also, verify that `jest-in-case` is compatible with your project's module system and Jest version.
Error: expect is not defined
This error can occur if Jest is not correctly configured or if a very old version of Jest is used, where `expect` might not be globally available or set up within the test environment when `jest-in-case` runs its callback.
fix
Ensure Jest is properly installed (`npm install --save-dev jest`), configured, and that `jest-in-case` is running within a standard Jest test file. Given the package's age, this might indicate fundamental incompatibility with your Jest setup.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
jestrequiredThis package is a Jest utility and implicitly requires Jest to run tests. Given its age (last updated 2017), it is likely only compatible with much older Jest versions (e.g., pre-Jest 20).
Agent activity
2 hits · last 30 days
node
2
Resources
jest-in-case — npm install jest-in-case · libregistry