expect.fail(...)
Explicitly forces failure.
expect.fail()
Explicit failure
expect.fail('Custom failure message')
Custom failure message
expect.fail('{0} was expected to be {1}', 0, 'zero');
0 was expected to be 'zero'
I case you want to rethrow an error, you should always use
expect.fail
, as it ensures that the error message will be correct
for the different error modes.
var error = new Error('throw me');
expect.fail(new Error(error));
Error: throw me
When you want to build a completely custom output, you can call
expect.fail
with a callback and receive a
magicpen instance that the
output can be written to.
expect.fail(function (output) {
'You have been a very bad boy!'.split(/ /).forEach(function (word, index) {
if (index > 0) { output.sp(); }
var style = index % 2 === 0 ? 'jsPrimitive' : 'jsString';
output[style](word);
});
});
You have been a very bad boy!