Skip to content

Commit

Permalink
Fix special casing of UnexpectedError in <function> to error/throw
Browse files Browse the repository at this point in the history
Pointed out by @alexjeffburke here:
#535 (comment)
  • Loading branch information
papandreou committed Dec 9, 2018
1 parent 9b30831 commit 057c5d8
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions lib/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -950,14 +950,7 @@ module.exports = expect => {
expect.errorMode = 'nested';
return expect.withError(
() => {
if (
error.isUnexpected &&
(typeof arg === 'string' || isRegExp(arg))
) {
return expect(error, 'to have message', arg);
} else {
return expect(error, 'to satisfy', arg);
}
return expect(error, 'to satisfy', arg);
},
e => {
e.originalError = error;
Expand Down Expand Up @@ -1054,15 +1047,7 @@ module.exports = expect => {
expect.errorMode = 'nested';
return expect.withError(
() => {
if (isUnexpected && (typeof arg === 'string' || isRegExp(arg))) {
return expect(
error.getErrorMessage('text').toString(),
'to satisfy',
arg
);
} else {
return expect(error, 'to satisfy', arg);
}
return expect(error, 'to satisfy', arg);
},
err => {
err.originalError = error;
Expand Down Expand Up @@ -1340,15 +1325,17 @@ module.exports = expect => {
);

expect.addAssertion(
'<Error> to [exhaustively] satisfy <regexp|string>',
'<Error> to [exhaustively] satisfy <regexp|string|any>',
(expect, { message }, value) =>
expect(message, 'to [exhaustively] satisfy', value)
);

expect.addAssertion(
'<Error> to [exhaustively] satisfy <any>',
(expect, { message }, value) =>
expect(message, 'to [exhaustively] satisfy', value)
'<UnexpectedError> to [exhaustively] satisfy <regexp|string>',
(expect, error, value) => {
expect.errorMode = 'bubble';
return expect(error, 'to have message', value);
}
);

expect.addAssertion(
Expand Down

0 comments on commit 057c5d8

Please sign in to comment.