Merge branch 'update-throwError-to-throw-objects' of https://github.com/terencehonles/jasmine
* Merges #1822 from @terencehonles
This commit is contained in:
@@ -8214,10 +8214,10 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
||||
* @name SpyStrategy#throwError
|
||||
* @since 2.0.0
|
||||
* @function
|
||||
* @param {Error|String} something Thing to throw
|
||||
* @param {Error|Object|String} something Thing to throw
|
||||
*/
|
||||
SpyStrategy.prototype.throwError = function(something) {
|
||||
var error = something instanceof Error ? something : new Error(something);
|
||||
var error = j$.isString_(something) ? new Error(something) : something;
|
||||
this.plan = function() {
|
||||
throw error;
|
||||
};
|
||||
|
||||
@@ -70,7 +70,7 @@ describe('SpyStrategy', function() {
|
||||
expect(originalFn).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('allows a non-Error to be thrown, wrapping it into an exception when executed', function() {
|
||||
it('allows a string to be thrown, wrapping it into an exception when executed', function() {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||
|
||||
@@ -82,6 +82,18 @@ describe('SpyStrategy', function() {
|
||||
expect(originalFn).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('allows a non-Error to be thrown when executed', function() {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
spyStrategy = new jasmineUnderTest.SpyStrategy({ fn: originalFn });
|
||||
|
||||
spyStrategy.throwError({ code: 'ESRCH' });
|
||||
|
||||
expect(function() {
|
||||
spyStrategy.exec();
|
||||
}).toThrow({ code: 'ESRCH' });
|
||||
expect(originalFn).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('allows a fake function to be called instead', function() {
|
||||
var originalFn = jasmine.createSpy('original'),
|
||||
fakeFn = jasmine.createSpy('fake').and.returnValue(67),
|
||||
|
||||
@@ -150,10 +150,10 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
||||
* @name SpyStrategy#throwError
|
||||
* @since 2.0.0
|
||||
* @function
|
||||
* @param {Error|String} something Thing to throw
|
||||
* @param {Error|Object|String} something Thing to throw
|
||||
*/
|
||||
SpyStrategy.prototype.throwError = function(something) {
|
||||
var error = something instanceof Error ? something : new Error(something);
|
||||
var error = j$.isString_(something) ? new Error(something) : something;
|
||||
this.plan = function() {
|
||||
throw error;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user