Skip to content

Commit

Permalink
Added test with params
Browse files Browse the repository at this point in the history
  • Loading branch information
jhsware committed Dec 24, 2022
1 parent a8b2e0d commit 9da806d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/inferno-router/__tests__/loaderOnRoute.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,32 @@ describe('A <Route> with loader in a MemoryRouter', () => {

expect(container.querySelector('#create').innerHTML).toContain(TEST);
});

it('Should recieve params in loader', async () => {
const TEXT = 'bubblegum';
const Component = (props, { router }) => {
const res = useLoaderData(props);
return <div><h1>{res?.message}</h1><p>{res?.slug}</p></div>
}
const loaderFunc = async ({params, request} = {}) => {
return { message: TEXT, slug: params?.slug }
}

const params = { slug: 'flowers' };
const initialData = {
'/:slug': { res: await loaderFunc({ params }), err: undefined, }
}

render(
<MemoryRouter initialEntries={['/flowers']} initialData={initialData}>
<Route path="/:slug" render={Component} loader={loaderFunc} />
</MemoryRouter>,
container
);

expect(container.innerHTML).toContain(TEXT);
expect(container.innerHTML).toContain('flowers');
});
});

describe('A <Route> with loader in a BrowserRouter', () => {
Expand Down

0 comments on commit 9da806d

Please sign in to comment.