I am using redux and react router.
I want to test that a route param shows up on the page.
test('route param is displayed', async () => {
const { queryByText } = customRender(
<EditCard />,
{
route: '/card/1554990887217',
}
);
const cardId = queryByText(/1554990887217/);
await waitForElement(() => cardId);
})
my custom render wraps router and redux like so:
export const customRender = (
ui,
{
route = '/',
history = createMemoryHistory({ initialEntries: [route] }),
initialState,
store = createStore(rootReducer, initialState),
...options
} = {}
) => ({
...rtl(
<Provider store={store}>
<Router history={history}>{ui}</Router>
</Provider>,
options
),
history,
});
The route param just doesn't show up in the test. It just errors with a time out.
It works on the page though, as in everything works as expected if I start the app up and test it manually.
You need to pass the route in as well.
const { queryByText } = render(
<Route path="/card/:cardId">
<EditCard />
</Route>,
{
route: '/card/1554990887217',
}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With