Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix special casing of UnexpectedError in <function> to error/throw #538

Merged
merged 1 commit into from
Dec 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 8 additions & 22 deletions lib/assertions.js
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 @@ -1048,21 +1041,12 @@ module.exports = expect => {
(expect, subject, arg) => {
expect.errorMode = 'nested';
return expect(subject, 'to throw').then(error => {
const isUnexpected = error && error._isUnexpected;
// in the presence of a matcher an error must have been thrown.

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 +1324,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