Complete the code to import the testing library for React components.
import { render } from '[1]';
The @testing-library/react package is the standard for testing React components in Next.js.
Complete the code to simulate a user clicking a button in a client component test.
import userEvent from '[1]';
The @testing-library/user-event package provides utilities to simulate user interactions like clicks.
Fix the error in the test by completing the render call with the correct component import.
import [1] from '@/components/SubmitButton'; render(<SubmitButton />);
Component names must match exactly and start with a capital letter in React.
Fill both blanks to wait for the button to appear and then click it in the test.
const button = await screen.[1]('button', { name: 'Submit' }); await userEvent.[2](button);
Use findByRole to wait for the button asynchronously, then click to simulate the user click.
Fill all three blanks to mock a fetch call, render a component, and check the displayed text.
global.fetch = jest.fn(() => Promise.resolve({
json: () => Promise.resolve({ message: [1] })
}));
render(<MessageDisplay />);
expect(await screen.findByText([2])).toBeInTheDocument();
expect(global.fetch).toHaveBeenCalledWith([3]);We mock fetch to return a message 'Hello World', check that text is displayed, and verify fetch was called with '/api/message'.