Added returnValues functionality to spy strategy
This commit is contained in:
@@ -46,6 +46,19 @@ describe("SpyStrategy", function() {
|
|||||||
expect(returnValue).toEqual(17);
|
expect(returnValue).toEqual(17);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("can return specified values in order specified when executed", function() {
|
||||||
|
var originalFn = jasmine.createSpy("original"),
|
||||||
|
spyStrategy = new j$.SpyStrategy({fn: originalFn});
|
||||||
|
|
||||||
|
spyStrategy.returnValues('value1', 'value2', 'value3');
|
||||||
|
|
||||||
|
expect(spyStrategy.exec()).toEqual('value1');
|
||||||
|
expect(spyStrategy.exec()).toEqual('value2');
|
||||||
|
expect(spyStrategy.exec()).toBe('value3');
|
||||||
|
expect(spyStrategy.exec()).toBeUndefined();
|
||||||
|
expect(originalFn).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it("allows an exception to be thrown when executed", function() {
|
it("allows an exception to be thrown when executed", function() {
|
||||||
var originalFn = jasmine.createSpy("original"),
|
var originalFn = jasmine.createSpy("original"),
|
||||||
spyStrategy = new j$.SpyStrategy({fn: originalFn});
|
spyStrategy = new j$.SpyStrategy({fn: originalFn});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
getJasmineRequireObj().SpyStrategy = function() {
|
getJasmineRequireObj().SpyStrategy = function () {
|
||||||
|
|
||||||
function SpyStrategy(options) {
|
function SpyStrategy(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
@@ -28,7 +28,15 @@ getJasmineRequireObj().SpyStrategy = function() {
|
|||||||
return getSpy();
|
return getSpy();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.throwError = function(something) {
|
this.returnValues = function () {
|
||||||
|
var values = Array.prototype.slice.call(arguments);
|
||||||
|
plan = function () {
|
||||||
|
return values.shift();
|
||||||
|
};
|
||||||
|
return getSpy();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.throwError = function (something) {
|
||||||
var error = (something instanceof Error) ? something : new Error(something);
|
var error = (something instanceof Error) ? something : new Error(something);
|
||||||
plan = function() {
|
plan = function() {
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
Reference in New Issue
Block a user