Created
May 23, 2018 17:35
-
-
Save jordanell/37fb333108d0aa265ed6dba3dbd82dfd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { mount as enzymeMount } from 'enzyme'; | |
import createHistory from 'history/createMemoryHistory'; | |
import React from 'react'; | |
import { Provider } from 'react-redux'; | |
import { ConnectedRouter } from 'react-router-redux'; | |
import Immutable from 'seamless-immutable'; | |
import initialize from 'src/store/initialize'; | |
/** | |
* Given a component, mounts it inside of Enzyme. | |
* | |
* @param {Node} component A React node to mount. | |
* @param {Object} state The default state to use in the Redux store. | |
* | |
* @return {Object} The mounted Enzyme object. | |
*/ | |
export default function mount(component, state = {}) { | |
let entry = '/'; | |
if (state.location) entry = `${state.location.pathname || '/'}${state.location.search}`; | |
const history = createHistory({ | |
initialEntries: [entry], | |
}); | |
const store = initialize(Immutable.from(state), history); | |
return enzymeMount( | |
<Provider store={store}> | |
<ConnectedRouter history={history}> | |
{component} | |
</ConnectedRouter> | |
</Provider> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment