Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Unit tests should avoid expect().not.toBeNull() and .not.toBe(null) #5479

@peterflynn

Description

@peterflynn

These forms will pass when foo === undefined, which is almost always not what was intended (masking real failures):

expect(foo).not.toBeNull();
expect(foo).not.toBe(null);

We should replace them with one of these safer forms:

expect(foo).toBeTruthy();
expect(foo).not.toEqual(null);

Personally I prefer toBeTruthy(), but we could pick either one to standardize on.

We have 60+ instances of the unsafe form in our codebase right now, including unit tests in extensions/default.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions