Skip to content

Commit 82daa5e

Browse files
qloniknovemberborn
authored andcommitted
Assert on expected error code, even when a number
1 parent 1e3b072 commit 82daa5e

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/assert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function assertExpectations({assertion, actual, expectations, message, prefix, s
215215
});
216216
}
217217

218-
if (typeof expectations.code === 'string' && actual.code !== expectations.code) {
218+
if (actual.code !== expectations.code) {
219219
throw new AssertionError({
220220
assertion,
221221
message,

test/assert.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,14 @@ test('.throws()', gather(t => {
858858
throw err;
859859
}, {code: 'ERR_TEST'});
860860
});
861+
862+
fails(t, () => {
863+
assertions.throws(() => {
864+
const err = new TypeError();
865+
err.code = 1;
866+
throw err;
867+
}, {code: 42});
868+
});
861869
}));
862870

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

0 commit comments

Comments
 (0)