Cleanup toThrowError constructor lookup to work in older IE

- Also use the existing browser detection for phantom
This commit is contained in:
Gregg Van Hove
2017-03-14 14:26:17 -07:00
parent e1f7ca51da
commit 75e652d6a7
4 changed files with 58 additions and 44 deletions

View File

@@ -29,8 +29,7 @@ getJasmineRequireObj().toThrowError = function(j$) {
}
// Get Error constructor of thrown
if (!thrown || !thrown.constructor || !thrown.constructor.constructor ||
!(thrown instanceof (thrown.constructor.constructor('return this')()).Error)) {
if (!isErrorObject(thrown)) {
fail.message = function() { return 'Expected function to throw an Error, but it threw ' + j$.pp(thrown) + '.'; };
return fail;
}
@@ -131,7 +130,18 @@ getJasmineRequireObj().toThrowError = function(j$) {
var Surrogate = function() {};
Surrogate.prototype = type.prototype;
return (new Surrogate()) instanceof Error;
return isErrorObject(new Surrogate());
}
function isErrorObject(thrown) {
if (thrown instanceof Error) {
return true;
}
if (thrown && thrown.constructor && thrown.constructor.constructor &&
(thrown instanceof (thrown.constructor.constructor('return this')()).Error)) {
return true;
}
return false;
}
}