You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1015 B
48 lines
1015 B
import React from 'react'
|
|
import { mount } from 'enzyme'
|
|
import { MemoryRouter } from 'react-router-dom'
|
|
import PropTypes from 'prop-types'
|
|
|
|
export function mountWithStore (component, store) {
|
|
const context = {
|
|
store,
|
|
}
|
|
return mount(component, { context })
|
|
}
|
|
|
|
export function mountWithRouter (component, store = {}, pathname = '/') {
|
|
|
|
// Instantiate router context
|
|
const router = {
|
|
history: new MemoryRouter().history,
|
|
route: {
|
|
location: {
|
|
pathname: pathname,
|
|
},
|
|
match: {},
|
|
},
|
|
}
|
|
|
|
const createContext = () => ({
|
|
context: {
|
|
router,
|
|
t: (str) => str,
|
|
metricsEvent: () => {},
|
|
store,
|
|
},
|
|
childContextTypes: {
|
|
router: PropTypes.object,
|
|
t: PropTypes.func,
|
|
metricsEvent: PropTypes.func,
|
|
store: PropTypes.object,
|
|
},
|
|
})
|
|
|
|
const Wrapper = () => (
|
|
<MemoryRouter initialEntries={[{ pathname }]} initialIndex={0}>
|
|
{component}
|
|
</MemoryRouter>
|
|
)
|
|
|
|
return mount(<Wrapper />, createContext())
|
|
}
|
|
|