Complete the code to import the testing library for server components in Next.js.
import { renderToString } from '[1]';
Next.js server components are tested by rendering them to a string using renderToString from react-dom/server.
Complete the code to render a server component called to a string.
const output = renderToString([1]);To render a server component to string, you pass the JSX element <MyComponent /> to renderToString.
Fix the error in this test code by completing the blank with the correct assertion method.
expect(output).[1]('Hello Server Component');
toBe which checks exact equality.toMatchObject which is for objects, not strings.Since output is a string of rendered HTML, toContain checks if the string includes the expected text.
Fill both blanks to import and test a server component named <Greeting> that takes a 'name' prop.
import Greeting from '[1]'; const output = renderToString(<Greeting name=[2] />);
The component is imported from a relative path '../components/Greeting'. The 'name' prop is a string, so it should be passed as a string literal.
Fill all three blanks to write a test that renders a server component <User> with a 'user' prop and asserts the output contains the user's name.
import User from '[1]'; const user = { name: 'Alice' }; const output = renderToString(<User [2]=[3] />); expect(output).toContain('Alice');
The component is imported from './components/User'. The prop name is user and the value is the variable user.