Skip to content

Latest commit

 

History

History
24 lines (15 loc) · 693 Bytes

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

File metadata and controls

24 lines (15 loc) · 693 Bytes

Disallow using .toBeDefined() matcher when it is known that variable is always defined (proper-tests/no-useless-matcher-to-be-defined)

💼 This rule is enabled in the ✅ recommended config.

Rule details

This rule disallows using toBeDefined() matcher when it is known that variable is always defined.

The following patterns are considered errors:

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

const foo = 'foo';
expect(foo).toBeDefined();

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

You should remove these expectations because they are redundant.