test-mock-return-in-hook
a mock return value set in a beforeEach instead of the setup factory
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, jest, beforeEach } from '@jest/globals';
const mockGetProfile = jest.fn<() => string>();
describe('subject', () => {
beforeEach(() => {
mockGetProfile.mockReturnValue('p.png');
});
test('reads the profile', () => {
expect(mockGetProfile()).toBe('p.png');
});
});
passsubject.unit.test.ts
import { expect, describe, test, jest } from '@jest/globals';
const mockGetVersion = jest.fn<() => string>();
const setupVersion = () => {
mockGetVersion.mockReturnValue('1.0.0');
return { version: '1.0.0' };
};
describe('subject', () => {
test('reads the version', () => {
const { version } = setupVersion();
expect(mockGetVersion()).toBe(version);
});
});
Turn it down
Both lines go in your lightsout.config.json.
"standards-checks": { "test-mock-return-in-hook": "advisory" }"standards-checks": { "test-mock-return-in-hook": "off" }