Skip to content

Commit 93c1d12

Browse files
committed
[Fix] in IE 8, TypeError does not inherit from Error
1 parent 82e7d71 commit 93c1d12

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ var nextTick = typeof setImmediate !== 'undefined'
3535
var safeSetTimeout = setTimeout;
3636
var safeClearTimeout = clearTimeout;
3737

38+
var isErrorConstructor = isProto(Error, TypeError) // IE 8 is `false` here
39+
? function isErrorConstructor(C) {
40+
return isProto(Error, C);
41+
}
42+
: function isErrorConstructor(C) {
43+
return isProto(Error, C)
44+
|| isProto(TypeError, C)
45+
|| isProto(RangeError, C)
46+
|| isProto(SyntaxError, C)
47+
|| isProto(ReferenceError, C)
48+
|| isProto(EvalError, C)
49+
|| isProto(URIError, C);
50+
};
51+
3852
// eslint-disable-next-line no-unused-vars
3953
function getTestArgs(name_, opts_, cb_) {
4054
var name = '(anonymous)';
@@ -829,7 +843,7 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) {
829843
if (typeof expected === 'function') {
830844
if (typeof expected.prototype !== 'undefined' && caught.error instanceof expected) {
831845
passed = true;
832-
} else if (isProto(Error, expected)) {
846+
} else if (isErrorConstructor(expected)) {
833847
passed = false;
834848
} else {
835849
passed = expected.call({}, caught.error) === true;

0 commit comments

Comments
 (0)