1

My test case looks something like this : In this test case, I've purposefully pushed the route in history object and given component as React.lazy(). Please let me know, what is incorrect here ?

    test("should route to Item search", async () => {
    const history = createMemoryHistory()
    history.push("/item-search");

        const { getByText } = render(
            <MemoryRouter initialEntries={['/item-search']}>
                <React.Suspense fallback={<div></div>}>
                    <Switch >
                        <Route exact path="/item-search" component={React.lazy(() => import('../ItemDetails/ItemDetails'))} />
                    </Switch>
                </React.Suspense>
            </MemoryRouter>
        );
        await waitFor(() => {
            expect(getByText('Item Details')).toBeInTheDocument();
        })
    });

enter image description here

Komal Thamke
  • 193
  • 1
  • 2
  • 11
  • Does this answer your question? https://stackoverflow.com/questions/66667827/react-testing-library-to-cover-the-lazy-load – Lin Du May 25 '23 at 07:36
  • I have tried this solution but still its not working for me. the lazy function is not covered. – Komal Thamke May 25 '23 at 08:00

0 Answers0