Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To log Redux actions in the Cypress console, you can follow these steps:

  1. Install the cypress-redux plugin by running npm install --save-dev cypress-redux.

  2. 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);
  1. In your Cypress test, use the cy.dispatch command to dispatch Redux actions:
cy.dispatch({
  type: 'ADD_TODO',
  payload: {
    id: 1,
    text: 'Buy milk',
    completed: false
  }
});
  1. Use the 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.