From b0f63edb426da8bc99cec9994d227a6bfa523303 Mon Sep 17 00:00:00 2001 From: Flarna Date: Wed, 7 Feb 2018 22:05:33 +0100 Subject: [PATCH 1/2] [sinon] allow SinonSpyCall for some asserts --- types/sinon/index.d.ts | 14 +++++++------- types/sinon/sinon-tests.ts | 12 ++++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/types/sinon/index.d.ts b/types/sinon/index.d.ts index f0433a694e..9348f3a690 100644 --- a/types/sinon/index.d.ts +++ b/types/sinon/index.d.ts @@ -353,19 +353,19 @@ declare namespace Sinon { calledThrice(spy: SinonSpy): void; callCount(spy: SinonSpy, count: number): void; callOrder(...spies: SinonSpy[]): void; - calledOn(spy: SinonSpy, obj: any): void; + calledOn(spy: SinonSpy | SinonSpyCall, obj: any): void; alwaysCalledOn(spy: SinonSpy, obj: any): void; - calledWith(spy: SinonSpy, ...args: any[]): void; + calledWith(spy: SinonSpy | SinonSpyCall, ...args: any[]): void; alwaysCalledWith(spy: SinonSpy, ...args: any[]): void; neverCalledWith(spy: SinonSpy, ...args: any[]): void; - calledWithExactly(spy: SinonSpy, ...args: any[]): void; + calledWithExactly(spy: SinonSpy | SinonSpyCall, ...args: any[]): void; alwaysCalledWithExactly(spy: SinonSpy, ...args: any[]): void; - calledWithMatch(spy: SinonSpy, ...args: any[]): void; + calledWithMatch(spy: SinonSpy | SinonSpyCall, ...args: any[]): void; alwaysCalledWithMatch(spy: SinonSpy, ...args: any[]): void; neverCalledWithMatch(spy: SinonSpy, ...args: any[]): void; - threw(spy: SinonSpy): void; - threw(spy: SinonSpy, exception: string): void; - threw(spy: SinonSpy, exception: any): void; + threw(spy: SinonSpy | SinonSpyCall): void; + threw(spy: SinonSpy | SinonSpyCall, exception: string): void; + threw(spy: SinonSpy | SinonSpyCall, exception: any): void; alwaysThrew(spy: SinonSpy): void; alwaysThrew(spy: SinonSpy, exception: string): void; alwaysThrew(spy: SinonSpy, exception: any): void; diff --git a/types/sinon/sinon-tests.ts b/types/sinon/sinon-tests.ts index 2e2286e538..16ec014b21 100644 --- a/types/sinon/sinon-tests.ts +++ b/types/sinon/sinon-tests.ts @@ -88,6 +88,18 @@ function testNine() { sinon.assert.calledWithMatch(callback, { x: 5 }); sinon.assert.alwaysCalledWithMatch(callback, { y: 5 }); sinon.assert.neverCalledWithMatch(callback, { x: 6 }); + + callback.call("this", "that"); + callback.throws("Error"); + try { + callback(15); + } catch (e) { } + sinon.assert.calledWith(callback.firstCall, { x: 5, y: 5}); + sinon.assert.calledWithExactly(callback.firstCall, { x: 5, y: 5 }); + sinon.assert.calledWithMatch(callback.firstCall, { x: 5 }); + sinon.assert.calledOn(callback.secondCall, "this"); + sinon.assert.threw(callback.thirdCall); + sinon.assert.threw(callback.thirdCall, "Error"); } function testAssert() { From ead8479b1c83efed59aa4ba636e28350b496c7e4 Mon Sep 17 00:00:00 2001 From: Flarna Date: Thu, 22 Feb 2018 22:41:22 +0100 Subject: [PATCH 2/2] Added calledWithNew() --- types/sinon/index.d.ts | 15 ++++++++------- types/sinon/sinon-tests.ts | 3 +++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/types/sinon/index.d.ts b/types/sinon/index.d.ts index 9348f3a690..5d3288068d 100644 --- a/types/sinon/index.d.ts +++ b/types/sinon/index.d.ts @@ -353,19 +353,20 @@ declare namespace Sinon { calledThrice(spy: SinonSpy): void; callCount(spy: SinonSpy, count: number): void; callOrder(...spies: SinonSpy[]): void; - calledOn(spy: SinonSpy | SinonSpyCall, obj: any): void; + calledOn(spyOrSpyCall: SinonSpy | SinonSpyCall, obj: any): void; alwaysCalledOn(spy: SinonSpy, obj: any): void; - calledWith(spy: SinonSpy | SinonSpyCall, ...args: any[]): void; + calledWith(spyOrSpyCall: SinonSpy | SinonSpyCall, ...args: any[]): void; alwaysCalledWith(spy: SinonSpy, ...args: any[]): void; neverCalledWith(spy: SinonSpy, ...args: any[]): void; - calledWithExactly(spy: SinonSpy | SinonSpyCall, ...args: any[]): void; + calledWithExactly(spyOrSpyCall: SinonSpy | SinonSpyCall, ...args: any[]): void; alwaysCalledWithExactly(spy: SinonSpy, ...args: any[]): void; - calledWithMatch(spy: SinonSpy | SinonSpyCall, ...args: any[]): void; + calledWithMatch(spyOrSpyCall: SinonSpy | SinonSpyCall, ...args: any[]): void; alwaysCalledWithMatch(spy: SinonSpy, ...args: any[]): void; neverCalledWithMatch(spy: SinonSpy, ...args: any[]): void; - threw(spy: SinonSpy | SinonSpyCall): void; - threw(spy: SinonSpy | SinonSpyCall, exception: string): void; - threw(spy: SinonSpy | SinonSpyCall, exception: any): void; + calledWithNew(spyOrSpyCall: SinonSpy | SinonSpyCall): void; + threw(spyOrSpyCall: SinonSpy | SinonSpyCall): void; + threw(spyOrSpyCall: SinonSpy | SinonSpyCall, exception: string): void; + threw(spyOrSpyCall: SinonSpy | SinonSpyCall, exception: any): void; alwaysThrew(spy: SinonSpy): void; alwaysThrew(spy: SinonSpy, exception: string): void; alwaysThrew(spy: SinonSpy, exception: any): void; diff --git a/types/sinon/sinon-tests.ts b/types/sinon/sinon-tests.ts index 16ec014b21..6ce2254596 100644 --- a/types/sinon/sinon-tests.ts +++ b/types/sinon/sinon-tests.ts @@ -100,6 +100,9 @@ function testNine() { sinon.assert.calledOn(callback.secondCall, "this"); sinon.assert.threw(callback.thirdCall); sinon.assert.threw(callback.thirdCall, "Error"); + new (callback as any)(); + sinon.assert.calledWithNew(callback); + sinon.assert.calledWithNew(callback.getCall(4)); } function testAssert() {