From c4711dad9ed631ce702a70da5384e6af9cd99312 Mon Sep 17 00:00:00 2001 From: wmzy <1256573276@qq.com> Date: Mon, 30 Sep 2019 18:10:44 +0800 Subject: [PATCH] fix throws TypeError when passing an arrow function --- lib/ext/_assert.js | 2 +- test/ext/assert.test.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/ext/_assert.js b/lib/ext/_assert.js index 8ca1036..7d0e6a2 100644 --- a/lib/ext/_assert.js +++ b/lib/ext/_assert.js @@ -206,7 +206,7 @@ function expectedException(actual, expected) { if (Object.prototype.toString.call(expected) == "[object RegExp]") { return expected.test(actual); - } else if (actual instanceof expected) { + } else if (expected.prototype && actual instanceof expected) { return true; } else if (expected.call({}, actual) === true) { return true; diff --git a/test/ext/assert.test.js b/test/ext/assert.test.js index 3aa26a0..5b73056 100644 --- a/test/ext/assert.test.js +++ b/test/ext/assert.test.js @@ -251,6 +251,9 @@ describe("assert", function() { ); threw = false; + // if passing a arrow function, catch all + assert.throws(makeBlock(thrower, TypeError), () => true); + // doesNotThrow should pass through all errors try { assert.doesNotThrow(makeBlock(thrower, TypeError), assert.AssertionError);