1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-29 15:50:28 +01:00
metamask-extension/test/lib/render-helpers.js

49 lines
1015 B
JavaScript
Raw Normal View History

import React from 'react'
import { mount } from 'enzyme'
import { MemoryRouter } from 'react-router-dom'
import PropTypes from 'prop-types'
2018-09-24 18:28:04 +02:00
export function mountWithStore (component, store) {
2018-09-24 18:28:04 +02:00
const context = {
store,
}
2019-12-03 21:50:55 +01:00
return mount(component, { context })
2018-09-24 18:28:04 +02:00
}
export function mountWithRouter (component, store = {}, pathname = '/') {
2018-09-24 18:28:04 +02:00
// Instantiate router context
const router = {
history: new MemoryRouter().history,
2018-09-24 18:28:04 +02:00
route: {
location: {
pathname: pathname,
},
2018-09-24 18:28:04 +02:00
match: {},
},
}
const createContext = () => ({
context: {
router,
2020-02-15 21:34:12 +01:00
t: (str) => str,
metricsEvent: () => {},
store,
},
childContextTypes: {
router: PropTypes.object,
t: PropTypes.func,
metricsEvent: PropTypes.func,
store: PropTypes.object,
},
2018-09-24 18:28:04 +02:00
})
const Wrapper = () => (
<MemoryRouter initialEntries={[{ pathname }]} initialIndex={0}>
{component}
</MemoryRouter>
)
return mount(<Wrapper />, createContext())
2018-09-24 18:28:04 +02:00
}