I'm currently testing our web application with cypress, and i'm having a paticular problem with the redux state being cleared between cy.visits. I'm Using cypress 8.6.0. We're using React with react-redux.
Current code in my test:
const state = { some: thing } // a normal object with key-value pairs
cy.visit('/B').then(() => {
cy.window()
.its('store')
.then(store => {
store.dispatch({
type: 'SET_ORDER',
payload: state,
});
});
});
The problem with this is sometimes, the route /B loads before the disptach event happens, and the test crashes because /B relies on some state being in my redux store to function.
so i thought something like this might work:
const state = { some: thing } // a normal object with key-value pairs
cy.visit('/A').then(() => {
cy.window()
.its('store')
.then(store => {
store.dispatch({
type: 'SET_ORDER',
payload: state,
});
});
})
cy.visit('/B'); // redux state gets cleared before going to /B
But it doesn't work since Cypress clears all state between tests (but also between cy.visits in the same it() test?).
Is there anyway i can preserve my redux state throughout my test? Or atleast just when going from /A to /B?