close

prefer-strict-equal

Configuration

rslint.config.ts
import { defineConfig, jestPlugin } from '@rslint/core';

export default defineConfig([
  jestPlugin.configs.recommended,
  {
    rules: {
      'jest/prefer-strict-equal': 'error',
    },
  },
]);

Rule Details

Prefer toStrictEqual() over toEqual(). While toEqual recursively checks every field of an object or array, it ignores undefined properties. This can lead to unexpected test passes and hide bugs. toStrictEqual() provides a stricter equality check that does not ignore undefined properties, making your tests more robust.

Examples of incorrect code for this rule:

expect({ a: 'a', b: undefined }).toEqual({ a: 'a' });

Examples of correct code for this rule:

expect({ a: 'a', b: undefined }).toStrictEqual({ a: 'a' });

Original Documentation