Questions tagged [redux-mock-store]

A JavaScript library used to make testing with redux easier, with support for redux async action creators and middleware.

View the repository on github

57 questions
27
votes
4 answers

Cannot read property '.then' of undefined when testing async action creators with redux and react

I'm trying to write some test using react, redux-mock-store and redux, but I keep getting and error. Maybe because my Promise has not yet been resolved? The fetchListing() action creator actually works when I try it on dev and production, but I'm…
intercoder
  • 2,171
  • 7
  • 23
  • 34
11
votes
2 answers

React testing library to cover the lazy load

How to cover the lazy load component in react testing library. import React, {lazy} from 'react'; const ownerInfo = lazy(() => import('../abc')) const compone = () => { return } export default compone test.spec.js …
10
votes
2 answers

Testing async actions with redux thunk

I am trying to test my action which has an async call. I use Thunk as my middleware. In the action below, I only dispatch and update the store if the server returns an OK response. export const SET_SUBSCRIBED = 'SET_SUBSCRIBED' export const…
Huy
  • 10,806
  • 13
  • 55
  • 99
9
votes
3 answers

Typescript, Unit Tests: Correct typing for Dispatching a Thunk with store.dispatch from redux-mock-store

Is there any way to correctly dispatch a Thunk from a store created with redux-mock-store ? Right now I am forced to use any type assertion store.dispatch(getCommissions()); As dispatch expects to provide plain Action [ts] Argument of type…
adyry
  • 613
  • 6
  • 15
7
votes
1 answer

How do I test an async action creator that calls another action with setTimeout

I have the following action that displays a notification and then removes it, and I´m trying to write a unit test for it but I can't seem to figure out how to mock setTimeout. export const addNotification = (text, notificationType = 'success', time…
6
votes
1 answer

Testing React Redux - cannot read properties of undefined, or wrapper undefined

Im having a bit of a problem setting up a Redux store in my component for my test suite. The problem is that even if I try a unconnected mount then the test throws errors looking for variables in authState. I have the following component: import…
Kyle Treman
  • 255
  • 1
  • 4
  • 9
6
votes
3 answers

Pass jest.fn() function to mapDispatchToProps in enzyme shallow render

Having very simple component: import PropTypes from 'prop-types' import React from 'react' import { connect } from 'react-redux' class MyComponent extends React.Component { componentWillMount() { if (this.props.shouldDoSth) { …
Filip Bartuzi
  • 5,711
  • 7
  • 54
  • 102
4
votes
1 answer

"Cannot read property 'getState' of undefined" when creating redux mock store

I am trying to test an input component in my React-Redux app and trying to create a mock of my redux store with 'redux-mock-store'. When I try to run the test I get "Cannot read property 'getState' of undefined" error, so I guess I'm not…
3
votes
1 answer

Set state of redux connected react component using enzyme

import configureMockStore from 'redux-mock-store'; import NavBar from '../components/NavBar/NavBar'; const mockStore = configureMockStore(middlewares); const store = mockStore(initialState); wrapper = mount(
3
votes
1 answer

Redux Mock Store giving 'Actions must be plain objects. Use custom middleware for async actions.'

I am trying to test some async code in my React app using redux-mock-store. const configureMockStore = require('redux-mock-store').default; const thunk = require("redux-thunk").default; const middlewares = [thunk]; const mockStore =…
darKnight
  • 5,651
  • 13
  • 47
  • 87
3
votes
1 answer

After Simulate('change') state is not updated

I've got a search filter component with an input inside it, and it's connected to redux. class SearchFilter extends PureComponent { constructor (props) { super(props); this.handleInputChange = this.handleInputChange.bind(this); …
3
votes
1 answer

how to mock saga generator function with jest and enzyme

I'm trying to test if my generator function is called when I call dispatch function. I'm doing something like: in my saga.js: import { takeLatest } from 'redux-saga/effects' import { SIGNIN_FORM_SUBMIT } from './constants' export default function*…
3
votes
0 answers

React / Jest: how to test store.dispatch is called

I am new in Redux and Jest and I am struggling on a problem. I want to write the test for this file: eventListeners.js import store from '@/store'; chrome.runtime.onMessage.addListener((request) => { if (request.type === 'OAUTH_SESSION_RESTORED')…
3
votes
2 answers

redux-mock-store getActions returns empty array

This is my action creator: export function signinUser({login, password}){ return function(dispatch){ axios.post('/auth/signin', {login, password}) .then((response)=>{ //-update state to…
kurumkan
  • 2,635
  • 3
  • 31
  • 55
2
votes
0 answers

how to mock the store.dispatch function when using mockStore? with jest

I have this in my react component console.log(await store.dispatch(getAndSaveImages())); and my test is: import configureMockStore from 'redux-mock-store'; import thunk from 'redux-thunk'; const middlewares = [thunk]; const mockStore =…
1
2 3 4