to have message

  • <Error> to have message <any>

Asserts that an Error instance the given message.

expect(new Error('foobar'), 'to have message', 'foobar');

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

expect(new Error('foobar'), 'to have message', 'barfoo');
expected Error('foobar'to have message 'barfoo'
  
expected 'foobar' to equal 'barfoo'
 
foobar
barfoo

The assertion uses to satisfy semantics, so you can also provide a regexp:

expect(new Error('foobar'), 'to have message', /bar$/);