Merge branch 'callfake-better-error' of https://github.com/kapke/jasmine into kapke-callfake-better-error

- Merges #1059
- Fixes #1016
This commit is contained in:
Gregg Van Hove
2016-08-15 09:34:03 -07:00
2 changed files with 17 additions and 2 deletions

View File

@@ -92,6 +92,18 @@ describe("SpyStrategy", function() {
expect(returnValue).toEqual(67);
});
it('throws an error when a non-function is passed to callFake strategy', function() {
var originalFn = jasmine.createSpy('original'),
invalidFakes = [5, 'foo', {}, true, false, null, void 0, new Date(), /.*/];
for (var i=0; i<invalidFakes.length; i++) {
var invalidFake = invalidFakes[i],
spyStrategy = new jasmineUnderTest.SpyStrategy({fn: originalFn});
expect(function() {spyStrategy.callFake(invalidFake);}).toThrowError('Argument passed to callFake should be a function, got ' + invalidFake);
}
});
it("allows a return to plan stubbing after another strategy", function() {
var originalFn = jasmine.createSpy("original"),
fakeFn = jasmine.createSpy("fake").and.returnValue(67),
@@ -103,7 +115,7 @@ describe("SpyStrategy", function() {
expect(originalFn).not.toHaveBeenCalled();
expect(returnValue).toEqual(67);
spyStrategy.stub();
returnValue = spyStrategy.exec();
@@ -118,7 +130,7 @@ describe("SpyStrategy", function() {
expect(spyStrategy.callThrough()).toBe(spy);
expect(spyStrategy.returnValue()).toBe(spy);
expect(spyStrategy.throwError()).toBe(spy);
expect(spyStrategy.callFake()).toBe(spy);
expect(spyStrategy.callFake(function() {})).toBe(spy);
expect(spyStrategy.stub()).toBe(spy);
});
});

View File

@@ -45,6 +45,9 @@ getJasmineRequireObj().SpyStrategy = function() {
};
this.callFake = function(fn) {
if(!(fn instanceof Function)) {
throw new Error('Argument passed to callFake should be a function, got ' + fn);
}
plan = fn;
return getSpy();
};