Skip to content

Latest commit

 

History

History
49 lines (29 loc) · 1.26 KB

prefer-to-be-object.md

File metadata and controls

49 lines (29 loc) · 1.26 KB

Suggest using toBeObject() (prefer-to-be-object)

🔧 This rule is automatically fixable by the --fix CLI option.

For expecting a value to be an object, jest-extended provides the toBeObject matcher.

Rule details

This rule triggers a warning if an expect assertion is found asserting that a value is an object using one of the following methods:

  • Comparing the result of <value> instanceof Object to a boolean value,
  • Calling the toBeInstanceOf matcher with the Object class.

The following patterns are considered warnings:

expect([] instanceof Object).toBe(true);

expect(myValue instanceof Object).toStrictEqual(false);

expect(theResults() instanceof Object).not.toBeFalse();

expect([]).toBeInstanceOf(true);

expect(myValue).resolves.toBeInstanceOf(Object);

expect(theResults()).not.toBeInstanceOf(Object);

The following patterns are not considered warnings:

expect({}).toBeObject();

expect(myValue).not.toBeObject();

expect(queryApi()).resolves.toBeObject();

expect(theResults()).toBeObject();

Further Reading