Skip to content

Latest commit

 

History

History
56 lines (33 loc) · 1.5 KB

prefer-to-be-array.md

File metadata and controls

56 lines (33 loc) · 1.5 KB

Suggest using toBeArray() (prefer-to-be-array)

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

For expecting a value to be an array, jest-extended provides the toBeArray matcher.

Rule details

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

  • Comparing the result of Array.isArary(<value>) to a boolean value,
  • Comparing the result of <value> instanceof Array to a boolean value,
  • Calling the toBeInstanceOf matcher with the Array class.

The following patterns are considered warnings:

expect(Array.isArray([])).toBe(true);

expect(Array.isArray(myValue)).toStrictEqual(false);

expect(Array.isArray(theResults())).not.toBeFalse();

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

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

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

expect([]).toBeInstanceOf(true);

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

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

The following patterns are not considered warnings:

expect(Array.isArray([])).toBeArray();

expect(Array.isArray(myValue)).not.toBeArray();

expect(myValue).resolves.toBeArray();

expect(Array.isArray(theResults())).toBeArray();

Further Reading