Skip to content

Files

Latest commit

 

History

History
22 lines (16 loc) · 567 Bytes

prefer-to-contain.md

File metadata and controls

22 lines (16 loc) · 567 Bytes

Pattern: Includes with boolean assertion

Issue: -

Description

Using includes() with boolean assertions provides less readable error messages. The toContain() matcher is specifically designed for checking array inclusion with clearer failure output.

Examples

Example of incorrect code:

expect(array.includes(value)).toBe(true);
expect(array.includes(value)).toEqual(true);
expect(array.includes(value)).toBe(false);

Example of correct code:

expect(array).toContain(value);
expect(array).not.toContain(value);