test-structure-arrange-act-assert-with-setup-factories
a test that does not read as arrange, act, assert with its arrangement in a `setup()` factory
Agent checkadvisory by defaultbasetests
The argument
Test Structure — Arrange-Act-Assert with Setup Factories
Every test follows Arrange-Act-Assert, with arrangement extracted into a named setup() factory. The test body stays small: call setup, act, assert.
describe('getAvatarUrl', () => {
test('returns the profile avatar when one exists', () => {
const { userProfile, appSettings } = setupAvatar({ profile: 'p.png' });
const avatarUrl = getAvatarUrl({ userProfile, appSettings });
expect(avatarUrl).toBe('p.png');
});
});
Rules:
The proof
failsrc/billing/getTotal.unit.test.ts
import { expect, describe, test } from '@jest/globals';
import { getTotal } from './getTotal';
describe('getTotal', () => {
test('multiplies the quantity by the unit price', () => {
// arrange
const quantity = 2;
const unitPrice = 50;
// act and assert in one breath, with the call nested in the matcher
expect(getTotal({ quantity, unitPrice })).toBe(100);
});
});
passsrc/billing/getTotal.unit.test.ts
import { expect, describe, test } from '@jest/globals';
import { getTotal } from './getTotal';
const setupOrder = ({ quantity = 2, unitPrice = 50 }: { quantity?: number; unitPrice?: number } = {}) => {
return { quantity, unitPrice };
};
describe('getTotal', () => {
test('multiplies the quantity by the unit price', () => {
const { quantity, unitPrice } = setupOrder();
const total = getTotal({ quantity, unitPrice });
expect(total).toBe(100);
});
});
Turn it down
Both lines go in your lightsout.config.json.
"standards-checks": { "test-structure-arrange-act-assert-with-setup-factories": "advisory" }"standards-checks": { "test-structure-arrange-act-assert-with-setup-factories": "off" }