如何编写单元测试以确保mapDispatchToProps正确返回被dispatch包装的action creator?
我目前正在使用Mocha和Enzyme进行测试。
这是我的容器组件。
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} ) => (
<div>
<Sidebar LayerActions={actions} />
<Map />
</div>
)
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)
const {firstAction} = props
),也可以是更全面的(const {layers, ...allOtherProps} = props
)。无论哪种方式,都要提取它们,然后使用这些道具呈现侧边栏。 - markerikson