Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat Request: add option to change getter to value #15

Open
zyf0330 opened this issue Oct 25, 2022 · 4 comments
Open

Feat Request: add option to change getter to value #15

zyf0330 opened this issue Oct 25, 2022 · 4 comments

Comments

@zyf0330
Copy link

zyf0330 commented Oct 25, 2022

To be compatible with sinon.stub(obj, "method"), else this code must be changed to sinon.stub(obj, "method").get(sinon.stub())

@AndyOGo
Copy link

AndyOGo commented May 23, 2023

I have the same problem with stubbing dynamic imports with sinon.

@fatso83
Copy link

fatso83 commented Aug 11, 2023

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: sinonjs/sinon#2403

@zyf0330
Copy link
Author

zyf0330 commented Aug 11, 2023

Thanks all of you.

@zyf0330 zyf0330 closed this as completed Aug 11, 2023
@fatso83
Copy link

fatso83 commented Aug 13, 2023

@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.

@zyf0330 zyf0330 reopened this Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants