Hi, How to stub an import with different values a...
# component-testing
a
Hi, How to stub an import with different values at different times in the same test case. Eg: -stub an import with value x before mounting a component -stub the same import with value y after doing click() on the component
w
Hi, I don’t think this is supported here. There are some related issues in GitHub, if you can find them here and comment about your use case that would be great: https://github.com/cypress-io/cypress/issues/21681
a
w
Have you taken a look at the gh issue to confirm it does explain your problem? Or if you could share the actual spec file that would be great. Off the top of my head I don’t think I’d expect what you described to work at the moment, but it’s hard to say for sure without looking at the code.
g
@abundant-gold-84344 can you create a small repo with a reproducible example
a
Here is the example repo(Not sure why cy.stub() is not working here): https://github.com/ElamuruganGR/Cypress-stub The comments in the screenshot is the actual scenario.
g
Ok, I don't think stubbing imports like this is working in
cypress/react
(it used to be part of cypress-react-unit-test, but is no longer) You need to use a custom webpack config with a plugin to enable shared loose import objects, like I have described in https://glebbahmutov.com/blog/stub-react-import/
a
@gray-kilobyte-89541 I added the plugin to make the stubbing of import work. and pushed to the same repo. Actually my question was *How to stub an import with different values at different times in the same test case? * In the screenshot (button.png) you can see 2 stubbings , for that i am getting the error:
Attempted to wrap useChange which is already wrapped
(result.png) The repo i shared in the beginning of the thread has the same code to reproduce the error.
g
4 Views