mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
9e6ba089d9
* Remove mountWithStore enzyme component wrapper in favor for renderWithProvider testing-library/react for tests Change dropdown component tests to testing-library/react
58 lines
1.2 KiB
JavaScript
58 lines
1.2 KiB
JavaScript
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'
|
|
|
|
export function mountWithRouter (component, store = {}, pathname = '/') {
|
|
|
|
// Instantiate router context
|
|
const router = {
|
|
history: new MemoryRouter().history,
|
|
route: {
|
|
location: {
|
|
pathname,
|
|
},
|
|
match: {},
|
|
},
|
|
}
|
|
|
|
const createContext = () => ({
|
|
context: {
|
|
router,
|
|
t: (str) => str,
|
|
metricsEvent: () => undefined,
|
|
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())
|
|
}
|
|
|
|
export function renderWithProvider (component, store) {
|
|
|
|
const Wrapper = () => (
|
|
<Provider store={store}>
|
|
<LegacyI18nProvider>
|
|
{ component }
|
|
</LegacyI18nProvider>
|
|
</Provider>
|
|
)
|
|
|
|
return render(<Wrapper />)
|
|
}
|