diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index 1bcd067d..240ae3f9 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1565,8 +1565,9 @@ getJasmineRequireObj().SpyStrategy = function() { }; this.callThrow = function(something) { + var error = (something instanceof Error) ? something : new Error(something); plan = function() { - throw something; + throw error; }; return getSpy(); }; diff --git a/spec/core/SpyStrategySpec.js b/spec/core/SpyStrategySpec.js index fb162d6c..496c8b73 100644 --- a/spec/core/SpyStrategySpec.js +++ b/spec/core/SpyStrategySpec.js @@ -50,9 +50,19 @@ describe("SpyStrategy", function() { var originalFn = jasmine.createSpy("original"), spyStrategy = new j$.SpyStrategy({fn: originalFn}); + spyStrategy.callThrow(new TypeError("bar")); + + expect(function() { spyStrategy.exec(); }).toThrowError(TypeError, "bar"); + expect(originalFn).not.toHaveBeenCalled(); + }); + + it("allows a non-Error to be thrown, wrapping it into an exception when executed", function() { + var originalFn = jasmine.createSpy("original"), + spyStrategy = new j$.SpyStrategy({fn: originalFn}); + spyStrategy.callThrow("bar"); - expect(function() { spyStrategy.exec(); }).toThrow("bar"); + expect(function() { spyStrategy.exec(); }).toThrowError(Error, "bar"); expect(originalFn).not.toHaveBeenCalled(); }); diff --git a/src/core/SpyStrategy.js b/src/core/SpyStrategy.js index 8a4a869e..fc6bb9fc 100644 --- a/src/core/SpyStrategy.js +++ b/src/core/SpyStrategy.js @@ -29,8 +29,9 @@ getJasmineRequireObj().SpyStrategy = function() { }; this.callThrow = function(something) { + var error = (something instanceof Error) ? something : new Error(something); plan = function() { - throw something; + throw error; }; return getSpy(); };