1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/test/lib/render-helpers.js

58 lines
1.2 KiB
JavaScript
Raw Normal View History

import React from 'react'
import { Provider } from 'react-redux'
import { render } from '@testing-library/react'
import { mount } from 'enzyme'
import { MemoryRouter } from 'react-router-dom'
import PropTypes from 'prop-types'
import { LegacyI18nProvider } from '../../ui/app/contexts/i18n'
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,
},
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: () => undefined,
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
}
export function renderWithProvider (component, store) {
const Wrapper = () => (
<Provider store={store}>
<LegacyI18nProvider>
{ component }
</LegacyI18nProvider>
</Provider>
)
return render(<Wrapper />)
}