Question: How to stub an import/function after an assertion?
Scenario:
- A button with customhook called. Based on the response of customhook (false/true), the button text will be changing.
- During initial render, customHook returns false and the text is xxxx.
- After clicking the button, the customHook returns true and the text will be changed to yyyy
Solution tried:
- mount the button (during which a customhook will be called and return false)
- assert the button text to be xxxx
- stubbed the custom hook to return true.
- cy.get("button").click();
- assert the new button text to be yyyy
Outputs:
- The above fails in step 2 . Looks like Stubbing (step 3) happened before step 2 assertion.
- If i dont stub, only step 5 fails.
So ultimately, based on the outputs, it is clear that Stubbing is not happening sequentially with assertion.
Can any one help me on this?