Asserts that an Error instance has a given message:

By default the assertion tests on the text representation of the error, but you can change that behaviour by providing the ansi or html flag.

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

You can use the ansi and html the following way:

expect(err, 'to have ansi message', 'foobar');
expect(err, 'to have html message', 'foobar');