Skip to content

Commit

Permalink
Assert on expected error code, even when a number
Browse files Browse the repository at this point in the history
  • Loading branch information
qlonik authored and novemberborn committed Mar 3, 2019
1 parent 1e3b072 commit 82daa5e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/assert.js
Expand Up @@ -215,7 +215,7 @@ function assertExpectations({assertion, actual, expectations, message, prefix, s
});
}

if (typeof expectations.code === 'string' && actual.code !== expectations.code) {
if (actual.code !== expectations.code) {
throw new AssertionError({
assertion,
message,
Expand Down
8 changes: 8 additions & 0 deletions test/assert.js
Expand Up @@ -858,6 +858,14 @@ test('.throws()', gather(t => {
throw err;
}, {code: 'ERR_TEST'});
});

fails(t, () => {
assertions.throws(() => {
const err = new TypeError();
err.code = 1;
throw err;
}, {code: 42});
});
}));

test('.throws() returns the thrown error', t => {
Expand Down

0 comments on commit 82daa5e

Please sign in to comment.