Open zyf0330 opened 2 years ago
I have the same problem with stubbing dynamic imports with sinon.
It is true that Sinon by itself cannot modify exports that immutable.
Since SWC is often setup to use CommonJS as the module system (which is the case here) for the transpiled code, you can easily achieve stubbing modules using Quibble or any other module loader hooks for CJS, and do stubbing in combination with Sinon, as described on the Sinon homepage. I even have an example for SWC using Quibble.
If you choose not to use a module loader, there are manual workarounds such as described here: https://github.com/sinonjs/sinon/issues/2403
Thanks all of you.
@zyf0330 You did not have to close it, it still makes sense IMHO. The current way it works makes SWC work differently from how ts-node
works, for instance, and as such tests need to be rewritten. I just mentioned some workarounds.
To be compatible with
sinon.stub(obj, "method")
, else this code must be changed tosinon.stub(obj, "method").get(sinon.stub())