From e59a8682539c76db01b64ec5083dd5a23ae2197f Mon Sep 17 00:00:00 2001 From: Roman Paradeev Date: Sat, 23 Feb 2019 23:50:35 +0500 Subject: [PATCH] Make sinon Bluebird-friendly --- types/sinon/ts3.1/index.d.ts | 2 +- types/sinon/ts3.1/sinon-tests.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/types/sinon/ts3.1/index.d.ts b/types/sinon/ts3.1/index.d.ts index 7123e75d49..b378e2a30b 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?: TReturnValue extends Promise ? TResolveValue : never): SinonStub; + resolves(value?: TReturnValue extends PromiseLike ? 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 2db25348ae..560ad7c6ae 100644 --- a/types/sinon/ts3.1/sinon-tests.ts +++ b/types/sinon/ts3.1/sinon-tests.ts @@ -1,4 +1,5 @@ import sinon = require("sinon"); +import Bluebird = require("bluebird"); function testSandbox() { const obj = {}; @@ -422,6 +423,7 @@ function testStub() { const obj = class { foo() { } promiseFunc() { return Promise.resolve('foo'); } + promiseLikeFunc() { return {} as any as Bluebird; } }; const instance = new obj(); @@ -430,10 +432,12 @@ function testStub() { const spy: sinon.SinonSpy = stub; - function promiseFunc(n: number) { return Promise.resolve('foo'); } const promiseStub = sinon.stub(instance, 'promiseFunc'); promiseStub.resolves('test'); + const promiseLikeStub = sinon.stub(instance, 'promiseLikeFunc'); + promiseLikeStub.resolves('test'); + sinon.stub(instance); stub.reset();