Skip to content

Files

Latest commit

 

History

History
21 lines (15 loc) · 541 Bytes

prefer-to-be-object.md

File metadata and controls

21 lines (15 loc) · 541 Bytes

Pattern: Indirect Object type checking in tests

Issue: -

Description

Using toBeInstanceOf(Object) or instanceof Object for type checking is less explicit than the dedicated toBeObject() method. Using toBeObject() makes the test's intention clearer and improves code readability.

Examples

Example of incorrect code:

expectTypeOf({}).toBeInstanceOf(Object);
expectTypeOf({} instanceof Object).toBeTruthy();

Example of correct code:

expectTypeOf({}).toBeObject();
expectTypeOf({}).toBeObject();