stub out resolves correctly

This commit is contained in:
Alec Flett
2018-12-14 10:56:49 -08:00
parent 9b9ce95bde
commit 92f3fa265a
2 changed files with 6 additions and 1 deletions
+1 -1
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?: any): SinonStub<TArgs, TReturnValue>;
resolves(value?: TReturnValue extends Promise<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.
+5
View File
@@ -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();