Last active
May 10, 2021 06:31
No need to export mapStateToProps and mapDispatchToProps for testing connected components!!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This mock will make sure that we are able to access mapStateToProps, mapDispatchToProps and reactComponent in the test file. | |
// To use this, just do `jest.mock('react-redux');` in your page.test.js file. | |
const mockDispatch = jest.fn((action) => action); | |
module.exports = { | |
connect: (mapStateToProps, mapDispatchToProps) => (reactComponent) => ({ | |
mapStateToProps, | |
mapDispatchToProps: (dispatch = mockDispatch, ownProps) => mapDispatchToProps(dispatch, ownProps), | |
reactComponent, | |
mockDispatch | |
}), | |
Provider: ({children}) => children | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@rgabs Thanks for this snippet !
This was exactly what I was looking for to test react-redux based components.
Thanks a ton!