Pattern: Indirect Object
type checking in tests
Issue: -
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.
Example of incorrect code:
expectTypeOf({}).toBeInstanceOf(Object);
expectTypeOf({} instanceof Object).toBeTruthy();
Example of correct code:
expectTypeOf({}).toBeObject();
expectTypeOf({}).toBeObject();