Cypress - How to stub an import/function after an assertion sequentially?

Viewed 21

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:

  1. mount the button (during which a customhook will be called and return false)
  2. assert the button text to be xxxx
  3. stubbed the custom hook to return true.
  4. cy.get("button").click();
  5. assert the new button text to be yyyy

Outputs:

  1. The above fails in step 2 . Looks like Stubbing (step 3) happened before step 2 assertion.
  2. 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?

0 Answers
Related