Open feargalWag opened 2 years ago
Hi @feargalWag,
The cy.mocksUseRouteVariant
does not need to reload the page to make effect. It should be able to be used many times inside the same test. The only idea that I have about what can be happening to you is that the specs are running before the change is really applied, because the change config command is async. Some things that you could do to check it:
cy.wait
command with some milliseconds (about 200 should be enough) after calling to cy.mocksApplyRouteVariant
, and verify that the mock has really changed.About your comment "cy.mocksRestoreRouteVariants doesn't seem to clear the request cache and allow me to get a new response", I don't understand it. This command is not related to cleaning any type of cache, it simply restores the mock to use the route variants originally defined in the collection (its like undoing all of the previous calls to cy.mocksUseRouteVariant
)
Is your feature request related to a problem? Please describe. When I have a test that requires me to make a request to the same endpoint more than once but receive a different response For example: if I have submitted a form and then re-request the same endpoint that I requested at the beginning of the test but the backend will now send back a new response because it can see that the user has changed state. I can get around this sometimes by triggering a
cy.reload()
or refreshing the page in some other way, but that's not always an option as the initial request might be made again when I refresh the page and I need it to return what it initially returned.Describe the solution you'd like The ability to call
cy.mocksUseRouteVartiant(routeName)
more than once in a test to get a different result so that I can switch the backend response for the endpoint out when the user performs an action.Describe alternatives you've considered Refreshing the page, but this isn't always an optino.
Additional context
Here's an example of what I'm talking about. I call
cy.mocksApplyRouteVariant('get-walker-application-state:about-me');
wherecy.mocksApplyRouteVariant()
is our internal name forcy.mocksUseRouteVariant()
with theget-walker-application-state:about-me
route, which returns a particular boolean set tofalse
.When I try and call the same route again with a different
id
get-walker-application-state:about-me-blocked
towards the end of the test where I want the aforementioned boolean to be set totrue
in the test then I receive the same response from that endpoint as I did initially.cy.mocksRestoreRouteVariants
doesn't seem to clear the request cache and allow me to get a new response.