Testing Library patterns for React component testing — queries, user events,
99
99%
Does it follow best practices?
Impact
100%
1.03xAverage score across 8 eval scenarios
Passed
No known issues
A development team is building a React application with global state provided through multiple context providers: a ThemeContext for light/dark mode, a BrowserRouter for client-side routing, and an AuthContext for the current user session. Several page-level components depend on all three providers being available in the tree.
The team has been writing tests by manually wrapping each component in all three providers inline for every test. This has become painful — every time a new provider is added, every test file needs updating. A senior developer has proposed a shared testing utility that wraps components automatically. You have been asked to set up this testing infrastructure and write tests for the UserProfilePage component to demonstrate the pattern. The component renders differently depending on authentication state and the current theme.
Create the following files:
src/test-utils.tsx: The shared test utility that provides the custom render functionsrc/AuthContext.tsx: The authentication context implementationsrc/ThemeContext.tsx: The theme context implementationsrc/UserProfilePage.tsx: The page component under testsrc/UserProfilePage.test.tsx: Tests for the page using the custom render utilityThe tests should cover at least: rendering the authenticated user's name, and rendering the unauthenticated (logged-out) state. The test file should use the shared testing utility you created.
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
skills
testing-library-patterns
verifiers