to have length

  • <array-like> [not] to have length <number>

Asserts that an array (or array-like object) has the specified length.

expect([1,2,3], 'to have length', 3);

In case of a failing expectation you get the following output:

expect([1,2,3], 'to have length', 4);
expected [ 123 ] to have length 4
  
expected 3 to be 4

This assertion can be negated using the not flag:

expect([1,2,3], 'not to have length', 4);

In case of a failing expectation you get the following output:

expect([1,2,3], 'not to have length', 3);
expected [ 123 ] not to have length 3