Change andThrow to always throw an Error

If an error is passed in, it is thrown, otherwise the argument passed
in is wrapped in an Error

[finishes #50607615][closes #372]
This commit is contained in:
Sheel Choksi
2013-09-05 23:02:22 -07:00
parent be0f7b4117
commit e3f0389ac2
3 changed files with 15 additions and 3 deletions

View File

@@ -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();
};

View File

@@ -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();
});

View File

@@ -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();
};