lightsoutAlpha

test-assert-in-hook

an assertion in a beforeEach instead of the test body

Deterministic checkblocking 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, beforeEach } from '@jest/globals';

describe('subject', () => {
	beforeEach(() => {
		expect(1 + 1).toBe(2);
	});

	test('adds two numbers', () => {
		expect(2 + 2).toBe(4);
	});
});
passsubject.unit.test.ts
import { expect, describe, test, afterEach } from '@jest/globals';

describe('subject', () => {
	afterEach(() => {
		expect(1 + 1).toBe(2);
	});

	test('adds two numbers', () => {
		expect(2 + 2).toBe(4);
	});
});

Turn it down

Both lines go in your lightsout.config.json.

"standards-checks": { "test-assert-in-hook": "advisory" }
"standards-checks": { "test-assert-in-hook": "off" }