Created
December 19, 2018 13:07
-
-
Save oieduardorabelo/f110776baa693c7dd899ed2b68d48035 to your computer and use it in GitHub Desktop.
Module mock in Jest using `react-redux/connect` as example
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
const connect = jest.fn((mapStateToProps) => { | |
const React = require.requireActual('react'); | |
const { rootReducer } = require.requireActual('../domains/root.reducer'); | |
const state = rootReducer({}, { type: '__jest-mock-react-redux__' }); | |
const fromConnectProps = mapStateToProps(state); | |
return jest.fn(Component => { | |
function Wrapper(props: any) { | |
const finalProps = { ...props, ...fromConnectProps }; | |
return React.createElement(Component, finalProps); | |
} | |
return Wrapper; | |
}); | |
}); | |
export { | |
connect | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment