Docs (4.0.0)
class Assertion method

toBeArray

Asserts that the value is an array, optionally with given length or elements.

toBeArray(match?: number | ReadonlyArray<any>): void

Summary

If a number parameter is provided, checks that the array length matches the given number. If an array parameter is provided, checks that both the length and all array elements match (strict equals).

Note
The NegatedAssertion.toBeArray() version of this method (i.e. .not.toBeArray()) only tests for array types, not length or elements.

Parameters

  • match — The array length, or all array elements to match

Example

// this succeeds:
let a = [1, 2, 3];
expect(a).toBeArray();
expect(a).toBeArray(3);
expect(a).toBeArray([1, 2, 3]);

// this fails:
expect(a).not.toBeArray();
expect(a).toBeArray(1);
expect(a).toBeArray([3, 2, 1]);

Related