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
Mark Stacey 4cc75eb9af
Remove tOrKey and tOrDefault functions from i18n context (#8211)
These two functions were not especially useful. `tOrDefault` was used
only by `tOrKey`, and `tOrKey` was only used in one place. All it did
was return the given `key` directly if it was falsey, so it was easily
replaced by a condition.
2020-03-19 01:03:20 -03:00

49 lines
1015 B
JavaScript

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())
}