Jest In Case: Parameterized Tests

1.0.2 · abandoned · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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 }
  ]);
});

view raw JSON →