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

Add a way to stub the dependency #27164

Closed
asekularaclf opened this issue Jun 29, 2023 · 2 comments
Closed

Add a way to stub the dependency #27164

asekularaclf opened this issue Jun 29, 2023 · 2 comments
Assignees

Comments

@asekularaclf
Copy link

What would you like?

It's a pain not to be able to mock/stub the dependency/node module when writing Cypress component tests.

Why is this needed?

Because a test software like Cypress should have a feature like this.

Other

No response

@mike-plummer mike-plummer self-assigned this Jun 29, 2023
@mike-plummer
Copy link
Contributor

Hi @asekularaclf - in order to properly respond to your request we need more information. Stubbing and Spying in component tests can be done using the cy.stub and cy.spy commands, however these have limitations depending on how your application is designed.

If your application is using a legacy module format like CommonJS and you are unable to use cy.stub/cy.spy then you may have identified a bug in which case we'll need a reproducible example and debug logs to help you troubleshoot.

If your project is using ESM then these APIs are unable to work as expected due to by-design limitations in ESM. There has been a lot of conversation in this ticket which provides context and potential workarounds.

If your application is using ESM and you're using Vite for bundling we have an experimental Vite plugin you can apply to try to work around some of the limitations of ESM. It is still in an alpha stage so it will likely require a few tweaks to get it working in your baseline but has been used successfully on several projects thus far.

Please let me know which of these scenarios is applicable to you so we can handle this ticket accordingly.

@lmiller1990
Copy link
Contributor

Needs more info - Cypress stub and spy are only going to work for frontend modules, since our code runs in the browser and does not have access to the Node.js context, except via cy.task.

If you've got a specific example you can share, I can help make recommendations. Right now there isn't enough info to action, so I'll close this. Happy to reopen with additional info.

@jennifer-shehane jennifer-shehane added stage: needs information Not enough info to reproduce the issue and removed stage: needs information Not enough info to reproduce the issue labels Oct 5, 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

4 participants