test-multiple-setups
more than one setup factory call in one test
Deterministic checkadvisory by defaultbasetests
The argument
This rule states its summary and proves it with an example.
The proof
failsubject.unit.test.ts
import { expect, describe, test } from '@jest/globals';
import { getLabel } from './getLabel';
const setupLabel = ({ name = 'Ada' }: { name?: string } = {}) => {
return { name };
};
const setupFallbackLabel = () => {
return { name: '' };
};
describe('getLabel', () => {
test('trims the name it is given', () => {
const { name } = setupLabel({ name: ' Ada ' });
const fallback = setupFallbackLabel();
const label = getLabel({ name: name || fallback.name });
expect(label).toBe('Ada');
});
});
pass
import { expect, describe, test } from '@jest/globals';
import { describeRule } from './describeRule';
const setupRule = ({ id = 'test-shared-let' }: { id?: string } = {}) => {
return { id };
};
// A rule about arrangement has to quote `setup()` in the guidance it renders,
// and the expected text is not a second call — it is what the assertion pins.
describe('describeRule', () => {
test('renders the guidance the rule ships', () => {
const { id } = setupRule();
const described = describeRule({ id });
expect(described.guidance).toBe('Arrange in a `setup()` factory that returns its locals as consts.');
});
});
Turn it down
Both lines go in your lightsout.config.json.
"standards-checks": { "test-multiple-setups": "advisory" }"standards-checks": { "test-multiple-setups": "off" }