Home How should I unit test mapDispatchToProps in Redux?
Reply: 0

How should I unit test mapDispatchToProps in Redux?

user998 Published in March 20, 2018, 5:33 am

How should write a unit test to ensure that mapDispatchToProps correctly returns action creators that are wrapped in the dispatch function?

I am currently using Mocha and Enzyme for testing.

Here is my container component.

import { Component } from 'react'
import { connect } from 'react-redux'
import Sidebar from '/components/Sidebar'
import Map from '/components/Map'
import * as LayerActions from '../actions/index'

// Use named export for unconnected component (for tests)
export const App = ({layers, actions} ) => (
     <Sidebar LayerActions={actions} />
     <Map /> 

export const mapStateToProps = state => ({
  layers: state.layers

export const mapDispatchToProps = dispatch => ({
    actions: bindActionCreators(LayerActions, dispatch)

// Use default export for the connected component (for app)
export default connect(mapStateToProps, mapDispatchToProps)(App)
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.299111 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO