forked from bldrs-ai/Share
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseRoutesMock.test.jsx
33 lines (27 loc) · 1007 Bytes
/
BaseRoutesMock.test.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import React from 'react'
import {MemoryRouter, Routes, Route} from 'react-router-dom'
import {render} from '@testing-library/react'
jest.mock('three')
test('mockRoutes', () => {
const testLabel = 'Test node label'
const {getByText} = render(<MockRoutes contentElt={testLabel}/>)
expect(getByText(testLabel)).toBeInTheDocument()
})
/**
* @param {Array} initialEntries For react-router MemoryRouter.
* @param {object} contentElt React component for Route.
* @return {React.Component} React component
*/
export default function MockRoutes({initialEntries = ['/'], contentElt} = {}) {
// TODO(pablo): would be better to not include the initialEntries
// attribute if not given, but don't know how to do this in React,
// so setting the default as defined in
// https://reactrouter.com/docs/en/v6/routers/memory-router.
return (
<MemoryRouter initialEntries={initialEntries}>
<Routes>
<Route path="/*" element={contentElt}/>
</Routes>
</MemoryRouter>
)
}