sinon: resolve any in worst case (#36119)

* sinon: resolve any in worst case

* add sinon test
This commit is contained in:
James Garbutt 2019-06-12 20:07:15 +01:00 committed by Ron Buckton
parent 6e43367819
commit 9d26e2f044
2 changed files with 7 additions and 1 deletions

View File

@ -404,7 +404,7 @@ declare namespace Sinon {
* The Promise library can be overwritten using the usingPromise method.
* Since sinon@2.0.0
*/
resolves(value?: TReturnValue extends PromiseLike<infer TResolveValue> ? TResolveValue : never): SinonStub<TArgs, TReturnValue>;
resolves(value?: TReturnValue extends PromiseLike<infer TResolveValue> ? TResolveValue : any): 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

@ -491,6 +491,7 @@ function testStub() {
foo(arg: string): number { return 1; }
promiseFunc() { return Promise.resolve('foo'); }
promiseLikeFunc() { return Promise.resolve('foo') as PromiseLike<string>; }
unresolvableReturnFunc(): any { return Promise.resolve(); }
fooDeep(arg: { s: string }): void { return undefined; }
};
const instance = new obj();
@ -501,6 +502,11 @@ function testStub() {
const promiseStub = sinon.stub(instance, 'promiseFunc');
promiseStub.resolves('test');
promiseStub.resolves(123); // $ExpectError
const promiseUnresolvableReturn =
sinon.stub(instance, 'unresolvableReturnFunc');
promiseUnresolvableReturn.resolves(['anything', 123, true]);
const promiseLikeStub = sinon.stub(instance, 'promiseLikeFunc');
promiseLikeStub.resolves('test');