Describe the bug
This was working in 7.3.2, but broke in 7.4.1.
Basically, when calling sinon.stub().resolves(...) as part of the second argument of sinon.createStubInstance(), I get undefined. It works as a standalone, however.
To Reproduce
Steps to reproduce the behavior:
Run the following test:
class X {
async test() {
return Promise.resolve(1)
}
}
it('is a buggy test', async () => {
const thing = sinon.createStubInstance(X, {
test: sinon.stub().resolves(2) as sinon.SinonStub<[], Promise<number>>
})
console.log(thing.test()) // undefined
}
Expected behavior
I would expect the console.log(thing.test()) to output 2
Screenshots
N/A
Context (please complete the following information):
Additional context
N/A
Not sure what could cause this in the changelog ... If you could run a git bisect run to find out which commit introduced this you can use this template: https://github.com/fatso83/git-bisect-scripts/blob/master/full-template.sh
git bisect reveals that createStubInstance was removed from the sinon API in this commit.
I can verify that it was broken in 7.4.0 as well
Also related to this, due to createStubInstance now using the (different) Sandbox implementation, it can no longer be called without explicitly specifying the Sandbox object binding.
So the following Typescript import no longer works (it worked in 7.3.2):
import { createStubInstance } from "sinon";
...
const thing = createStubInstance(X);
which results in TypeError: Cannot read property 'stub' of undefined
This could be resolved by replacing this.stub with sandbox.stub here: https://github.com/sinonjs/sinon/blob/671330cebf271b05afea01fdadcc111130b2b4af/lib/sinon/sandbox.js#L58
This issue, and some others, has revealed to me that, while we have great unit test coverage, some integration tests for the API is missing. We should have a little test suite that just tests for and executes a base test for all of the exposed API methods. Then stuff like this wouldn't happen nilly-willy.
PS. Great work on digging into this guys!
This has been fixed with #2073 and released as [email protected] 馃殌
Most helpful comment
This issue, and some others, has revealed to me that, while we have great unit test coverage, some integration tests for the API is missing. We should have a little test suite that just tests for and executes a base test for all of the exposed API methods. Then stuff like this wouldn't happen nilly-willy.