mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-01 12:42:58 +08:00
Add returnValues() function to SpyAnd interface (#9175)
This commit is contained in:
committed by
Masahiro Wakame
parent
e843172c97
commit
36a1be34db
@@ -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;
|
||||
|
||||
|
||||
2
jasmine/jasmine.d.ts
vendored
2
jasmine/jasmine.d.ts
vendored
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user