.toHaveLength(number)

Use .toHaveLength to check that an object has a .length property and it is set to a certain numeric value.

This is especially useful for checking arrays or strings size.

  1. expect([1, 2, 3]).toHaveLength(3);
  2. expect('abc').toHaveLength(3);
  3. expect('').not.toHaveLength(5);