1 | initial version |
To log Redux actions in the Cypress console, you can follow these steps:
Install the cypress-redux
plugin by running npm install --save-dev cypress-redux
.
In your cypress/support/index.js
file, add the following code to register the plugin:
import reduxPlugin from 'cypress-redux';
import { createStore } from 'redux';
import rootReducer from '../../src/reducers'; // Import your root reducer
const store = createStore(rootReducer); // Create a store with your root reducer
reduxPlugin(store);
cy.dispatch
command to dispatch Redux actions:cy.dispatch({
type: 'ADD_TODO',
payload: {
id: 1,
text: 'Buy milk',
completed: false
}
});
cy.window()
command to access the Redux store and log the actions:cy.window().then(window => {
const actions = window.store.getActions(); // Get all dispatched actions
console.log(actions); // Log the actions in the Cypress console
});
This will log all dispatched actions in the Cypress console.