Complete the code to import the testing library for React in Next.js.
import { render } from '[1]';
We use @testing-library/react to render components for testing in Next.js.
Complete the code to write a simple test that checks if a Next.js component renders text.
test('renders welcome message', () => { const { getByText } = render(<HomePage />); expect(getByText('[1]')).toBeInTheDocument(); });
The test checks if the text 'Welcome to Next.js' appears in the component.
Fix the error in the test by completing the missing import for the Next.js component.
import [1] from '../pages/index';
The default export from ../pages/index is usually named HomePage in examples.
Fill both blanks to mock a Next.js router method in a test.
jest.mock('next/router', () => ({ useRouter: () => ({ [1]: jest.fn(), [2]: jest.fn() }) }));
We mock push and replace methods of Next.js router to test navigation.
Fill all three blanks to write a test that waits for data to load in a Next.js component.
import { render, screen, [1] } from '@testing-library/react'; render(<DataComponent />); const item = await [2](() => screen.getByText('[3]')); expect(item).toBeInTheDocument();
We import waitFor to wait for async changes, use waitFor with screen.getByText to find text, and check for 'Loading complete' text.