From 30e6ba2925d6e1d8faf559284b8267aee2b72884 Mon Sep 17 00:00:00 2001 From: Jonathan Little Date: Wed, 22 Mar 2017 09:32:01 -0700 Subject: [PATCH] Fix for issue #15320: Updates for SinonJS 2.x API including promise rejection/resolution from stubs. --- types/sinon/index.d.ts | 17 ++++++++--------- types/sinon/sinon-tests.ts | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/types/sinon/index.d.ts b/types/sinon/index.d.ts index e4ba1ad612..0dd6d29fce 100644 --- a/types/sinon/index.d.ts +++ b/types/sinon/index.d.ts @@ -1,6 +1,6 @@ -// Type definitions for Sinon 1.16.0 +// Type definitions for Sinon 2.1.0 // Project: http://sinonjs.org/ -// Definitions by: William Sears +// Definitions by: William Sears , Jonathan Little // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // sinon uses DOM dependencies which are absent in browserless envoronment like node.js @@ -96,11 +96,16 @@ declare namespace Sinon { interface SinonStub extends SinonSpy { resetBehavior(): void; + resetHistory(): void; returns(obj: any): SinonStub; returnsArg(index: number): SinonStub; returnsThis(): SinonStub; + resolves(value: any): SinonStub; throws(type?: string): SinonStub; throws(obj: any): SinonStub; + rejects(): SinonStub; + rejects(errorType: string): SinonStub; + rejects(value: any): SinonStub; callsArg(index: number): SinonStub; callThrough(): SinonStub; callsArgOn(index: number, context: any): SinonStub; @@ -369,6 +374,7 @@ declare namespace Sinon { array: SinonMatcher; regexp: SinonMatcher; date: SinonMatcher; + symbol: SinonMatcher; same(obj: any): SinonMatcher; typeOf(type: string): SinonMatcher; instanceOf(type: any): SinonMatcher; @@ -421,17 +427,10 @@ declare namespace Sinon { (...args: any[]): any; } - interface SinonStatic { - config: SinonTestConfig; - test(fn: (...args: any[]) => any): SinonTestWrapper; - testCase(tests: any): any; - } - // Utility overridables interface SinonStatic { createStubInstance(constructor: any): any; format(obj: any): string; - log(message: string): void; restore(object: any): void; } } diff --git a/types/sinon/sinon-tests.ts b/types/sinon/sinon-tests.ts index 9a35166324..afd20c2e18 100644 --- a/types/sinon/sinon-tests.ts +++ b/types/sinon/sinon-tests.ts @@ -100,6 +100,23 @@ function testSandbox() { sandbox.restore(); } +function testPromises() { + var resolveStub = sinon.stub().resolves(10); + var rejectStub1 = sinon.stub().rejects(); + var rejectsStub2 = sinon.stub().rejects(new Error('Specified error')); + var rejectsStub2 = sinon.stub().rejects("TypeError"); +} + +function testSymbolMatch() { + var stub = sinon.stub(); + stub(Symbol('TestSymbol')); + stub.calledWithMatch(sinon.match.symbol); +} + +function testResetHistory() { + sinon.stub().resetHistory(); +} + testOne(); testTwo(); testThree(); @@ -109,6 +126,9 @@ testSix(); testSeven(); testEight(); testNine(); +testPromises(); +testSymbolMatch(); +testResetHistory(); var clock = sinon.useFakeTimers(); clock.setSystemTime(1000);