Adding toHaveBeenCalledBefore matcher to jasmine

This commit is contained in:
Dale Caffull
2017-09-14 13:56:49 +01:00
parent acc37d8b9d
commit 417f0c2de9
2 changed files with 12 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
// Type definitions for Jasmine 2.5.2
// Type definitions for Jasmine 2.6.0
// Project: http://jasmine.github.io/
// Definitions by: Boris Yankov <https://github.com/borisyankov>, Theodore Brown <https://github.com/theodorejb>, David Pärsson <https://github.com/davidparsson>, Gabe Moothart <https://github.com/gmoothart>, Lukas Zech <https://github.com/lukas-zech-software>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -427,6 +427,7 @@ declare namespace jasmine {
toBeTruthy(expectationFailOutput?: any): boolean;
toBeFalsy(expectationFailOutput?: any): boolean;
toHaveBeenCalled(): boolean;
toHaveBeenCalledBefore(expected: Spy): boolean;
toHaveBeenCalledWith(...params: any[]): boolean;
toHaveBeenCalledTimes(expected: number): boolean;
toContain(expected: any, expectationFailOutput?: any): boolean;

View File

@@ -270,19 +270,24 @@ describe("Pending specs", () => {
});
describe("A spy", () => {
var foo: any, bar: any = null;
var foo: any, bar: any, baz: any = null;
beforeEach(() => {
foo = {
setBar: (value: any) => {
bar = value;
},
setBaz: (value: any) => {
baz = value;
}
};
spyOn(foo, 'setBar');
spyOn(foo, 'setBaz');
foo.setBar(123);
foo.setBar(456, 'another param');
foo.setBaz(789);
});
it("tracks that the spy was called", () => {
@@ -294,6 +299,10 @@ describe("A spy", () => {
expect(foo.setBar).toHaveBeenCalledWith(456, 'another param');
});
it("tracks the order in which spies were called", () => {
expect(foo.setBar).toHaveBeenCalledBefore(foo.setBaz);
});
it("stops all execution on a function", () => {
expect(bar).toBeNull();
});