diff --git a/jasmine/jasmine-tests.ts b/jasmine/jasmine-tests.ts index 45b2d155a6..d873d2716b 100644 --- a/jasmine/jasmine-tests.ts +++ b/jasmine/jasmine-tests.ts @@ -358,6 +358,40 @@ describe("A spy, when configured to fake a return value", function () { }); }); +describe("A spy, when configured to fake a series of return values", function() { + var foo: any, bar: any; + + beforeEach(function() { + foo = { + setBar: function(value: any) { + bar = value; + }, + getBar: function() { + return bar; + } + }; + + spyOn(foo, "getBar").and.returnValues("fetched first", "fetched second"); + + foo.setBar(123); + }); + + it("tracks that the spy was called", function() { + foo.getBar(123); + expect(foo.getBar).toHaveBeenCalled(); + }); + + it("should not affect other functions", function() { + expect(bar).toEqual(123); + }); + + it("when called multiple times returns the requested values in order", function() { + expect(foo.getBar()).toEqual("fetched first"); + expect(foo.getBar()).toEqual("fetched second"); + expect(foo.getBar()).toBeUndefined(); + }); +}); + describe("A spy, when configured with an alternate implementation", function () { var foo: any, bar: any, fetchedBar: any; diff --git a/jasmine/jasmine.d.ts b/jasmine/jasmine.d.ts index aa3acdfbf8..9841a74fc8 100644 --- a/jasmine/jasmine.d.ts +++ b/jasmine/jasmine.d.ts @@ -431,6 +431,8 @@ declare namespace jasmine { callThrough(): Spy; /** By chaining the spy with and.returnValue, all calls to the function will return a specific value. */ returnValue(val: any): Spy; + /** By chaining the spy with and.returnValues, all calls to the function will return specific values in order until it reaches the end of the return values list. */ + returnValues(...values: any[]): Spy; /** By chaining the spy with and.callFake, all calls to the spy will delegate to the supplied function. */ callFake(fn: Function): Spy; /** By chaining the spy with and.throwError, all calls to the spy will throw the specified value. */