This rule recommends using toBeUndefined
instead of the more generic matcher
toBe(undefined)
.
This rule forces a codebase to be consistent when expecting values to be
undefined
in unit tests.
The "always"
option (default) prefers toBeUndefined()
. Select this option
if you'd like developers to use a matcher that tests specifically for
undefined
.
Examples of incorrect code for the "always"
option:
expect(value).toBe(undefined);
expect(value).toBe(undefined, 'with an explanation');
Examples of correct code for the "always"
option:
expect(value).toBeUndefined();
expect(value).toBeUndefined('with an explanation');
The "never"
option prefers toBe(undefined)
. Select this option if you'd
like developers to use the toBe
matcher consistently, whether testing
for undefined
or not.
Examples of incorrect code for the "never"
option:
expect(value).toBeUndefined();
expect(value).toBeUndefined('with an explanation');
Examples of correct code for the "never"
option:
expect(value).toBe(undefined);
expect(value).toBe(undefined, 'with an explanation');