lightsoutAlpha

test-strict-equal-matcher

`toStrictEqual` with an asymmetric matcher — strict in name only

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

describe('subject', () => {
	test('matches part of the result', () => {
		const result = { id: 'a', size: 2 };

		expect(result).toStrictEqual(expect.objectContaining({ id: 'a' }));
	});
});
passsubject.unit.test.ts
import { expect, describe, test } from '@jest/globals';

// A test whose subject reads code as text passes that code in as data. This is
// a mention of the pairing the rule bans, not one — the rule reads what the
// file does, not what it quotes.
const sampleLine = 'expect(result).toStrictEqual(expect.any(String));';

describe('subject', () => {
	test('matches the whole result', () => {
		const result = { id: 'a', size: 2 };

		expect(result).toStrictEqual({ id: 'a', size: 2 });
	});

	test('carries its sample line untouched', () => {
		expect(sampleLine).toContain('toStrictEqual');
	});
});

Turn it down

Both lines go in your lightsout.config.json.

"standards-checks": { "test-strict-equal-matcher": "advisory" }
"standards-checks": { "test-strict-equal-matcher": "off" }