From 92f3fa265a5be8d5d5c14f2fdf9a12579da0fa41 Mon Sep 17 00:00:00 2001 From: Alec Flett Date: Fri, 14 Dec 2018 10:56:49 -0800 Subject: [PATCH] stub out resolves correctly --- types/sinon/ts3.1/index.d.ts | 2 +- types/sinon/ts3.1/sinon-tests.ts | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/types/sinon/ts3.1/index.d.ts b/types/sinon/ts3.1/index.d.ts index bc91a3285a..afdf6358b5 100644 --- a/types/sinon/ts3.1/index.d.ts +++ b/types/sinon/ts3.1/index.d.ts @@ -399,7 +399,7 @@ declare namespace Sinon { * The Promise library can be overwritten using the usingPromise method. * Since sinon@2.0.0 */ - resolves(value?: any): SinonStub; + resolves(value?: TReturnValue extends Promise ? TResolveValue : never): SinonStub; /** * Causes the stub to return a Promise which resolves to the argument at the provided index. * stub.resolvesArg(0); causes the stub to return a Promise which resolves to the first argument. diff --git a/types/sinon/ts3.1/sinon-tests.ts b/types/sinon/ts3.1/sinon-tests.ts index b892f22980..98838d1754 100644 --- a/types/sinon/ts3.1/sinon-tests.ts +++ b/types/sinon/ts3.1/sinon-tests.ts @@ -417,6 +417,7 @@ function testSpy() { function testStub() { const obj = class { foo() { } + promiseFunc() { return Promise.resolve('foo'); } }; const instance = new obj(); @@ -425,6 +426,10 @@ function testStub() { const spy: sinon.SinonSpy = stub; + function promiseFunc(n: number) { return Promise.resolve('foo'); } + const promiseStub = sinon.stub(instance, 'promiseFunc'); + promiseStub.resolves('test'); + sinon.stub(instance); stub.reset();