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:
@@ -1565,8 +1565,9 @@ getJasmineRequireObj().SpyStrategy = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.callThrow = function(something) {
|
this.callThrow = function(something) {
|
||||||
|
var error = (something instanceof Error) ? something : new Error(something);
|
||||||
plan = function() {
|
plan = function() {
|
||||||
throw something;
|
throw error;
|
||||||
};
|
};
|
||||||
return getSpy();
|
return getSpy();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -50,9 +50,19 @@ describe("SpyStrategy", function() {
|
|||||||
var originalFn = jasmine.createSpy("original"),
|
var originalFn = jasmine.createSpy("original"),
|
||||||
spyStrategy = new j$.SpyStrategy({fn: originalFn});
|
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");
|
spyStrategy.callThrow("bar");
|
||||||
|
|
||||||
expect(function() { spyStrategy.exec(); }).toThrow("bar");
|
expect(function() { spyStrategy.exec(); }).toThrowError(Error, "bar");
|
||||||
expect(originalFn).not.toHaveBeenCalled();
|
expect(originalFn).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,9 @@ getJasmineRequireObj().SpyStrategy = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.callThrow = function(something) {
|
this.callThrow = function(something) {
|
||||||
|
var error = (something instanceof Error) ? something : new Error(something);
|
||||||
plan = function() {
|
plan = function() {
|
||||||
throw something;
|
throw error;
|
||||||
};
|
};
|
||||||
return getSpy();
|
return getSpy();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user