Skip to content

Latest commit

 

History

History
24 lines (15 loc) · 674 Bytes

no-useless-matcher-to-be-null.md

File metadata and controls

24 lines (15 loc) · 674 Bytes

Disallow using .toBeNull() when TypeScript types conflict with it (proper-tests/no-useless-matcher-to-be-null)

💼 This rule is enabled in the ✅ recommended config.

Rule details

This rule disallows using not.toBeNull() matcher when it is known that variable is always not null.

The following patterns are considered errors:

const fooWithType: string = 'foo';
expect(foo).not.toBeNull();

const foo = 'foo';
expect(foo).not.toBeNull();

const user = repository.findByIdOrThrow(123); // return type is `User`
expect(user).not.toBeNull();

You should remove these expectations because they are redundant.