lightsoutAlpha

test-mock-wrapper-untyped

a `jest.mock` factory wrapper that discards the arguments it is called with

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

const mockSaveOrder = jest.fn<(params: { id: string }) => string>();

jest.mock('@/orders/saveOrder', () => ({
	saveOrder: (...args: unknown[]) => mockSaveOrder(args[0] as { id: string }),
}));

describe('subject', () => {
	test('saves the order', () => {
		mockSaveOrder.mockReturnValue('ok');

		expect(mockSaveOrder({ id: 'a' })).toBe('ok');
	});
});
passsubject.unit.test.ts
import { expect, describe, test, jest } from '@jest/globals';

const mockSaveOrder = jest.fn<(params: { id: string }) => string>();

jest.mock('@/orders/saveOrder', () => ({
	saveOrder: (params: { id: string }) => mockSaveOrder(params),
}));

describe('subject', () => {
	test('forwards the order id', () => {
		mockSaveOrder.mockReturnValue('ok');

		expect(mockSaveOrder).toHaveBeenCalledWith({ id: 'a' });
	});
});

Turn it down

Both lines go in your lightsout.config.json.

"standards-checks": { "test-mock-wrapper-untyped": "advisory" }
"standards-checks": { "test-mock-wrapper-untyped": "off" }