useEffect(() => fetch( /api/users/$userId ) .then(res => res.json()) .then(setUser) , [userId])
| Query | Returns | When to use | |-------|---------|--------------| | getByRole | Element | - accessible to screen readers | | getByLabelText | Input/textarea | Form fields with labels | | getByPlaceholderText | Input | Fallback when no label | | getByText | Element | Buttons, paragraphs, headings | | getByDisplayValue | Input | Current value of form field | | getByAltText | Image | Images with alt text | | getByTitle | Element | Title attribute | | getByTestId | Element | Last resort - avoid when possible | React Testing Library and Jest- The Complete Guide
screen is a convenience object that exports all query methods. Always use screen instead of destructuring render . useEffect(() => fetch( /api/users/$userId )