to have length

  • <string> [not] to have length <number>

Asserts that the string has the specified length.

expect('Hello world', 'to have length', 11);

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

expect('Hello world', 'to have length', 12);
expected 'Hello world' to have length 12
  
expected 11 to be 12

This assertion can be negated using the not flag:

expect('Hello world', 'not to have length', 12);

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

expect('Hello world', 'not to have length', 11);
expected 'Hello world' not to have length 11