Quiz Yourself on Components
This quiz will test what you have learned in this chapter.
1
We have the following test that checks that the TopBar
component renders a checkout button:
test("TopBar renders checkout button", async () => {
render(<TopBar />);
expect(screen.getByText("Checkout")).toBeInTheDocument();
});
The following error occurs when the test is executed: “You should not use <Link>
outside a <Router>
.”
How can this error be resolved?
A)
Change the render
call to the following:
render(
<BrowserRouter>
<HomePage />
</BrowserRouter>
);
B)
Change the render
call to the following:
render(
<MemoryRouter>
<HomePage />
</MemoryRouter>
);
C)
Remove the Link
components inside TopBar
and replace them with a
elements.
D)
Remove the test. We can’t test components that reference Link
components.
Question 1 of 40 attempted
Get hands-on with 1400+ tech skills courses.