Back to all reviewers

Use screen queries

mui/material-ui
Based on 2 comments
TSX

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.

Testing TSX

Reviewer Prompt

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.

2
Comments Analyzed
TSX
Primary Language
Testing
Category

Source Discussions