From 417f0c2de9ceabb77dd2d9e217f880cdc0c91efc Mon Sep 17 00:00:00 2001 From: Dale Caffull Date: Thu, 14 Sep 2017 13:56:49 +0100 Subject: [PATCH] Adding toHaveBeenCalledBefore matcher to jasmine --- types/jasmine/index.d.ts | 3 ++- types/jasmine/jasmine-tests.ts | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/types/jasmine/index.d.ts b/types/jasmine/index.d.ts index 001d044dd5..e5a7cd3ba3 100644 --- a/types/jasmine/index.d.ts +++ b/types/jasmine/index.d.ts @@ -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 , Theodore Brown , David Pärsson , Gabe Moothart , Lukas Zech // 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; diff --git a/types/jasmine/jasmine-tests.ts b/types/jasmine/jasmine-tests.ts index 017896ebf5..8c4fff54f7 100644 --- a/types/jasmine/jasmine-tests.ts +++ b/types/jasmine/jasmine-tests.ts @@ -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(); });