From ff029b37b5b2fb95c6f2252713b14586f86786cb Mon Sep 17 00:00:00 2001 From: Gregg Van Hove Date: Thu, 9 Apr 2015 15:36:59 -0700 Subject: [PATCH] Use `instanceof` when checking Error types in toThrowError Fixes #819 --- spec/core/matchers/toThrowErrorSpec.js | 2 -- src/core/matchers/toThrowError.js | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/spec/core/matchers/toThrowErrorSpec.js b/spec/core/matchers/toThrowErrorSpec.js index 1c0faee1..43b3b8ed 100644 --- a/spec/core/matchers/toThrowErrorSpec.js +++ b/spec/core/matchers/toThrowErrorSpec.js @@ -170,7 +170,6 @@ describe("toThrowError", function() { result; CustomError.prototype = new Error(); - CustomError.prototype.constructor = CustomError; result = matcher.compare(fn, CustomError); @@ -222,7 +221,6 @@ describe("toThrowError", function() { result; CustomError.prototype = new Error(); - CustomError.prototype.constructor = CustomError; result = matcher.compare(fn, CustomError, "foo"); diff --git a/src/core/matchers/toThrowError.js b/src/core/matchers/toThrowError.js index 5fbe1b2c..41ab793d 100644 --- a/src/core/matchers/toThrowError.js +++ b/src/core/matchers/toThrowError.js @@ -109,7 +109,7 @@ getJasmineRequireObj().toThrowError = function(j$) { return expected === null && errorType === null; }, matches: function(error) { - return (errorType === null || error.constructor === errorType) && + return (errorType === null || error instanceof errorType) && (expected === null || messageMatch(error.message)); } };