Hey folks, I have a component stubbing question. I...
# component-testing
e
Hey folks, I have a component stubbing question. I have a function in my codebase:
Copy code
export default useSpecificHook(...args)
When stubbing this function I get an odd error:
Copy code
import useSpecificHook from ".";

...

cy.stub(useSpecificHook).returns({});
That returns
cy.stub(...).returns is not a function
which doesn't make sense since it should chain like SinonJS. Any idea what I could be doing wrong? Are methods stub-able?
a
Try to import the file like below > import * as Hooks from "{path}/useSpecificHook"; and stub like below > cy.stub(Hooks, "useSpecificHook").returns({}); I think, this should work.
e
Thank you so much @abundant-gold-84344. Interesting thing happens now. I get a new error:
Cannot stub non-existent own property useSpecificHook
. Any ideas?
a
Are you trying to use the hook from node_modules? (Transpiled code)
@elegant-psychiatrist-66173 Without seeing the exact scenario, it's difficult to suggest. Can you give the sample code which should reflect the same error? Also pls take a look at the below issue in GitHub, you may get some solution from the following issue chats. If not pls send the sample code. Just code is enough, no need to setup a repo. https://github.com/sinonjs/sinon/issues/1720
e
Thank you @abundant-gold-84344. I will read through this first, and if i run into issues I will try to create a repo with this issue. There's a lot of proprietary code so that might take a day or two to recreate.
3 Views