Replies: 3 comments 5 replies
-
|
Beta Was this translation helpful? Give feedback.
-
Trying to do sth similar and came across this post. I'm quite new to FE/Testing and not sure if this is the best practice, at least it seems to work for me. Please kindly correct me if there will be side effects doing so Added this in the entry component of my React App from CRA (e.x App.js)
then access it in Cypress with
|
Beta Was this translation helpful? Give feedback.
-
I could make it work in this way useEffect(() => {
if (window.Cypress) {
window.store = useMyStore;
}
}, []) cy.window().its('store').invoke('getState').invoke('setName', 'asdasd');
cy.window()
.its('store')
.invoke('getState')
.its('name')
.should('eq', 'asdasd'); |
Beta Was this translation helpful? Give feedback.
-
I'm trying to access the react component state in Cypress tests. There are some tutorials on how to do it with redux, e.g.
https://glebbahmutov.com/blog/react-app-actions/
https://www.cypress.io/blog/2018/11/14/testing-redux-store/
https://dev.to/damcosset/testing-a-redux-data-store-with-cypress-io-36gd
however, they don't seem to be applicable to zustand. Is there any way to access and edit applications state (set by zustand's
useStore
from shared state) outside of the app? I thought that https://github.com/bahmutov/cypress-react-app-actions will do its job (as it allows to get react component state), however, the returned state is always empty which obviously is incorrect.Beta Was this translation helpful? Give feedback.
All reactions