From 93c1d12380e230adff29a86a030dd9c1fa544afc Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 14 Feb 2024 12:46:24 -0800 Subject: [PATCH] [Fix] in IE 8, `TypeError` does not inherit from `Error` --- lib/test.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/test.js b/lib/test.js index fd651966..bdcfb9f2 100644 --- a/lib/test.js +++ b/lib/test.js @@ -35,6 +35,20 @@ var nextTick = typeof setImmediate !== 'undefined' var safeSetTimeout = setTimeout; var safeClearTimeout = clearTimeout; +var isErrorConstructor = isProto(Error, TypeError) // IE 8 is `false` here + ? function isErrorConstructor(C) { + return isProto(Error, C); + } + : function isErrorConstructor(C) { + return isProto(Error, C) + || isProto(TypeError, C) + || isProto(RangeError, C) + || isProto(SyntaxError, C) + || isProto(ReferenceError, C) + || isProto(EvalError, C) + || isProto(URIError, C); + }; + // eslint-disable-next-line no-unused-vars function getTestArgs(name_, opts_, cb_) { var name = '(anonymous)'; @@ -829,7 +843,7 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) { if (typeof expected === 'function') { if (typeof expected.prototype !== 'undefined' && caught.error instanceof expected) { passed = true; - } else if (isProto(Error, expected)) { + } else if (isErrorConstructor(expected)) { passed = false; } else { passed = expected.call({}, caught.error) === true;