mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 20:40:20 +00:00
Add support for chaining and calls on Jasmine spies
This commit is contained in:
@@ -400,6 +400,44 @@ describe("A spy, when configured to throw a value", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("A spy, when configured with multiple actions", function () {
|
||||
var foo: any, bar: any, fetchedBar: any;
|
||||
|
||||
beforeEach(function () {
|
||||
foo = {
|
||||
setBar: function (value: any) {
|
||||
bar = value;
|
||||
},
|
||||
getBar: function () {
|
||||
return bar;
|
||||
}
|
||||
};
|
||||
|
||||
spyOn(foo, 'getBar').and.callThrough().and.callFake(() => {
|
||||
this.fakeCalled = true;
|
||||
});
|
||||
|
||||
foo.setBar(123);
|
||||
fetchedBar = foo.getBar();
|
||||
});
|
||||
|
||||
it("tracks that the spy was called", function () {
|
||||
expect(foo.getBar).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should not effect other functions", function () {
|
||||
expect(bar).toEqual(123);
|
||||
});
|
||||
|
||||
it("when called returns the requested value", function () {
|
||||
expect(fetchedBar).toEqual(123);
|
||||
});
|
||||
|
||||
it("should have called the fake implementation", function () {
|
||||
expect(this.fakeCalled).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("A spy", function () {
|
||||
var foo: any, bar: any = null;
|
||||
|
||||
|
||||
Vendored
+4
-4
@@ -1,6 +1,6 @@
|
||||
// Type definitions for Jasmine 2.1
|
||||
// Project: http://pivotal.github.com/jasmine/
|
||||
// Definitions by: Boris Yankov <https://github.com/borisyankov/>, Theodore Brown <https://github.com/theodorejb>
|
||||
// Definitions by: Boris Yankov <https://github.com/borisyankov/>, Theodore Brown <https://github.com/theodorejb>, David Pärsson <https://github.com/davidparsson/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
|
||||
@@ -372,15 +372,15 @@ declare module jasmine {
|
||||
|
||||
interface SpyAnd {
|
||||
/** By chaining the spy with and.callThrough, the spy will still track all calls to it but in addition it will delegate to the actual implementation. */
|
||||
callThrough(): void;
|
||||
callThrough(): Spy;
|
||||
/** By chaining the spy with and.returnValue, all calls to the function will return a specific value. */
|
||||
returnValue(val: any): void;
|
||||
/** By chaining the spy with and.callFake, all calls to the spy will delegate to the supplied function. */
|
||||
callFake(fn: Function): void;
|
||||
callFake(fn: Function): Spy;
|
||||
/** By chaining the spy with and.throwError, all calls to the spy will throw the specified value. */
|
||||
throwError(msg: string): void;
|
||||
/** When a calling strategy is used for a spy, the original stubbing behavior can be returned at any time with and.stub. */
|
||||
stub(): void;
|
||||
stub(): Spy;
|
||||
}
|
||||
|
||||
interface Calls {
|
||||
|
||||
Reference in New Issue
Block a user