Parameterized tests declare one test or suite for every row in a dataset. Vitest and Bun evaluate the dataset when the each
declaration is registered. If the dataset is empty, no test cases or suites are registered, so the test body never runs. Jest also evaluates the
dataset when the declaration is registered. For test.each and it.each, Jest registers a failing test when the dataset is
empty; for describe.each, Jest throws an error during registration.
This can happen when test cases are removed during a refactoring or when a parameterized test is created before its cases are added. In Vitest and Bun, the test suite can still pass while providing no coverage for the behavior that the declaration appears to test. In Jest, an empty test dataset causes a generated test to fail, while an empty suite dataset causes registration to fail.
This rule covers Jest, Vitest, and Bun parameterized test declarations (test.each and it.each) and suite declarations
(describe.each, Vitest’s suite.each, and Bun’s describe.each). It only reports datasets that are statically
known to be empty; dynamic datasets and intentionally skipped declarations are not reported.
Provide at least one dataset row before registering the parameterized test or suite. If the test is deliberately disabled, declare it as skipped explicitly instead.
test.each(
[], // Noncompliant: this parameterized test uses an empty dataset, so Jest registers a failing test
)('doubles %i', (value, expected) => {
expect(double(value)).toBe(expected);
});
test.each([
[1, 2],
[2, 4],
])('doubles %i', (value, expected) => {
expect(double(value)).toBe(expected);
});
import { suite, test } from 'vitest';
const cases: Array<[number, number]> = [];
suite.each(
cases, // Noncompliant: this parameterized suite has no cases, so its body never runs
)('doubles %i', (value, expected) => {
test('returns the expected value', () => {
expect(double(value)).toBe(expected);
});
});
cases.push([1, 2]); // too late: the suite has already been registered
import { suite, test } from 'vitest';
const cases: Array<[number, number]> = [[1, 2]];
suite.each(cases)('doubles %i', (value, expected) => {
test('returns the expected value', () => {
expect(double(value)).toBe(expected);
});
});
import { test } from 'bun:test';
test.each(
[], // Noncompliant: this parameterized test has no cases, so its body never runs
)('doubles %i', (value, expected) => {
expect(double(value)).toBe(expected);
});
import { test } from 'bun:test';
test.each([
[1, 2],
])('doubles %i', (value, expected) => {
expect(double(value)).toBe(expected);
});
test.each(table)(name, fn, timeout)describe.each(table)(name, fn,
timeout)test.eachdescribe.eachtest.each and
describe.each