prefer-to-be
Configuration
rslint.config.ts
Rule Details
This rule promotes the use of the most appropriate equality matcher in expect
assertions, which results in more idiomatic tests and clearer failure output:
- For primitive literals (numbers, strings, booleans), prefer
toBe()overtoEqual()ortoStrictEqual(). The matchers behave identically here, buttoBe()reads more naturally. - For
null,undefined, andNaN, prefer the dedicated matcherstoBeNull(),toBeUndefined()/toBeDefined(), andtoBeNaN(). They produce more descriptive error messages thantoBe(),toEqual(), ortoStrictEqual().
The rule is reported through the following messages:
Examples of incorrect code for this rule:
Examples of correct code for this rule: