Merge pull request #33344 from sameoldmadness/make-sinon-bluebird-friendly

Make sinon Bluebird-friendly
This commit is contained in:
Jesse Trinity
2019-02-27 10:42:18 -08:00
committed by GitHub
2 changed files with 6 additions and 2 deletions

View File

@@ -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<infer TResolveValue> ? TResolveValue : never): SinonStub<TArgs, TReturnValue>;
resolves(value?: TReturnValue extends PromiseLike<infer TResolveValue> ? TResolveValue : never): SinonStub<TArgs, TReturnValue>;
/**
* 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.

View File

@@ -1,4 +1,5 @@
import sinon = require("sinon");
import Bluebird = require("bluebird");
function testSandbox() {
const obj = {};
@@ -426,6 +427,7 @@ function testStub() {
const obj = class {
foo() { }
promiseFunc() { return Promise.resolve('foo'); }
promiseLikeFunc() { return {} as any as Bluebird<string>; }
};
const instance = new obj();
@@ -434,10 +436,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();