When writing component tests, prefer using global `screen` queries from Testing Library instead of container-specific queries or passing query functions as parameters. This approach keeps the test environment simple and consistent across the codebase.
When writing component tests, prefer using global screen
queries from Testing Library instead of container-specific queries or passing query functions as parameters. This approach keeps the test environment simple and consistent across the codebase.
Instead of:
const { container } = render(<TextareaAutosize style= />);
const input = container.querySelector<HTMLTextAreaElement>('textarea')!;
Use:
render(<TextareaAutosize style= />);
const input = screen.getByRole('textbox');
Similarly, avoid passing query functions as parameters to test utilities when the global screen
object can be used directly. This reduces complexity and follows the Testing Library’s recommendation of using queries that resemble how users interact with your components.
Enter the URL of a public GitHub repository