mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Adding withArgs method to Spy interface as per Jasmine's docs for v3.3
This commit is contained in:
parent
36a32d8a72
commit
00f1245e59
1
types/jasmine/index.d.ts
vendored
1
types/jasmine/index.d.ts
vendored
@ -639,6 +639,7 @@ declare namespace jasmine {
|
||||
calls: Calls;
|
||||
mostRecentCall: { args: any[]; };
|
||||
argsForCall: any[];
|
||||
withArgs(...args: any[]): Spy;
|
||||
}
|
||||
|
||||
type SpyObj<T> = T & {
|
||||
|
||||
@ -469,6 +469,40 @@ describe("A spy, when configured with an alternate implementation", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("A spy, when configured with alternate implementations for specified arguments", () => {
|
||||
var foo: any, bar: any, fetchedBar: any;
|
||||
|
||||
beforeEach(() => {
|
||||
foo = {
|
||||
setBar: (value: any) => {
|
||||
bar = value;
|
||||
},
|
||||
getBar: () => {
|
||||
return bar;
|
||||
}
|
||||
};
|
||||
|
||||
spyOn(foo, "getBar")
|
||||
.withArgs(1, "2")
|
||||
.and.callFake(() => 1002);
|
||||
|
||||
foo.setBar(123);
|
||||
fetchedBar = foo.getBar(1, "2");
|
||||
});
|
||||
|
||||
it("tracks that the spy was called", () => {
|
||||
expect(foo.getBar).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should not effect other functions", () => {
|
||||
expect(bar).toEqual(123);
|
||||
});
|
||||
|
||||
it("when called returns the requested value", () => {
|
||||
expect(fetchedBar).toEqual(1002);
|
||||
});
|
||||
});
|
||||
|
||||
describe("A spy, when configured to throw a value", () => {
|
||||
var foo: any, bar: any;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user