Начал изучать тестирование. Как протестировать вызов метода
showGroup в
mapDispatchToProps?
import React, { Component } from 'react'
import { withStyles } from '@material-ui/core/styles'
import { connect } from 'react-redux'
import DrawerContent from '../components/DrawerContent'
import RandomComponent from '../components/RandomComponent'
import { showGroup } from '../actions/interfaceActions'
export class FilterPanel extends Component {
render() {
const { classes, theme, showGroup } = this.props
return (
<div>
<DrawerContent showGroup={showGroup} />
<RandomComponent />
</div>
)
}
}
const mapStateToProps = (store) => ({
...
})
const mapDispatchToProps = (dispatch) => ({
showGroup: (group) => {dispatch(showGroup(group))}
})
export default withStyles(
styles
)(connect(
mapStateToProps,
mapDispatchToProps
)(FilterPanel))
Сам тест:
Enzyme.configure({ adapter: new Adapter() })
describe('FilterPanel', () => {
const initialState = {
showDrawer: false,
filterPanel: {},
language: 'rus',
dictonary: {}
}
const mockStore = configureStore()
let store, container
beforeEach(() => {
store = mockStore(initialState)
container = shallow(<ConnectedFilterPanel store={store} />)
})
test('Check HANDLE_SHOW_GROUP action on dispatching', () => {
store.dispatch(showGroup("value"))
const action = store.getActions()
expect(action[0].type).toEqual("HANDLE_SHOW_GROUP")
})
})