react-testing
Test React components with RTL and Jest/Vitest. Use when writing React component tests with React Testing Library, Jest, or Vitest.
- 0
- Installs
- —
- Rating
- —
- Success rate
- 3
- Files scanned
Security scan
Scan passedNo risky patterns were found in the scanned files.
Content sha256 256e8bce3fc047e5… — run codexguild_scan_skills after installing to verify your local copy.
Static analysis is a first line of defense, not a guarantee. Read the source
SKILL.md
React Testing
Priority: P1 (HIGH)
Core Philosophy
- Test User Behavior, Not Implementation Mechanics: Tests should verify that the application works for end users, rather than checking how components are implemented internally.
- Resistance to Refactoring: Refactoring component internal state, props, or hooks must never break passing tests as long as the user-visible behavior remains unchanged.
Core Rule Anchors (Four Pillars Enforcement)
[WEB-TEST-01]Tripartite Naming & AAA Cadence: Test names must followMethod_Scenario_ExpectedBehaviorand adhere strictly to Arrange-Act-Assert. Example:SubmitOrder_WhenCreditLimitExceeded_DisplaysBlockedBanner.[WEB-TEST-02]Accessible Roles & UserEvent: Always useuserEvent.setup()for user interactions (await user.click(...)) and query elements via accessible roles (getByRole,findByLabelText). AvoidfireEventand ban arbitrary CSS / DOM hierarchy selectors.[WEB-TEST-03]Ban on Component State & Prop Inspection: Never inspect internal component state or props directly. Never write trivial echo assertions (expect(true).toBe(true)). Assert on visible user outcomes and DOM state changes.[WEB-TEST-04]Mock Service Worker (MSW) Network Mocking: Intercept network requests at the HTTP boundary via MSW rather than mocking internal Apollo Client hooks (useQuery) or Redux dispatchers. Tests must verify true end-to-end component data flow.[WEB-TEST-05]Bug-First Regression Lock: Every PR resolving a bug ticket or with titlefix(...)must introduce a test reproducing the defect prior to the fix.
Implementation Guidelines
- Standards: Use React Testing Library (RTL) with Vitest or Jest. Follow Arrange-Act-Assert (AAA) pattern (
[WEB-TEST-01]). - User-Centric Selection: Prioritize accessible queries:
getByRole,findByLabelText,getByText. Treatdata-testidonly as an explicit fallback for complex UI elements, and strictly ban CSS class or DOM hierarchy selectors ([WEB-TEST-02]). - Behavioral Assertions: Test user workflows using
userEvent.setup()(e.g.,const user = userEvent.setup(); await user.click(...)) rather than firing raw synthetic DOM events withfireEvent([WEB-TEST-02]). - Network Boundary Mocking (MSW): Mock API network requests at the HTTP layer using Mock Service Worker (MSW) instead of mocking Apollo Client hooks (
useQuery,useMutation) or Redux dispatchers. This validates end-to-end component data flow without leaking mock internals. Never call real APIs in unit/integration tests ([WEB-TEST-04]). - Asynchrony: Use
await screen.findBy*for elements rendered after asynchronous actions. UsewaitFor(() => ...)only for complex non-element updates or assertion retries. - Architecture: Test behavior, not implementation. Never inspect component internal
stateorprops([WEB-TEST-03]). - Mocks: Mock expensive third-party libraries (e.g.,
framer-motion,react-router) or heavy assets at the boundary to speed up tests. - Visuals: Use Snapshot testing sparingly for stable, small UI components. Banish large snapshot tests of dynamic pages. Manual a11y checks with
jest-axe.
Anti-Patterns & Banned Smells
[WEB-TEST-01]Vague test names: Banish non-descriptive names; adhere toMethod_Scenario_ExpectedBehavior.[WEB-TEST-02]No Synthetic Events or CSS Selectors: AvoidfireEvent; always useuserEvent.setup(). Ban querying by CSS classes or DOM hierarchy.[WEB-TEST-03]No Testing Implementation Details: Never inspect or assert on component internalstateorpropsdirectly.[WEB-TEST-04]No Hook / Dispatcher Mocking: Do not mock Apollo Client hooks or Redux dispatchers directly; intercept network requests via MSW handlers.[WEB-TEST-05]No Bug Fix Without Reproduction: Ban bug fix PRs without defect reproduction tests.- No Large Dynamic Snapshots: Ban snapshot tests of dynamic pages, lists, or complex containers.
- No Shallow Rendering: Render the full component tree with required providers.
- No Wait-for-Find: Prefer
await screen.findBy*overwaitFor(() => screen.getBy*).
References
See references/REFERENCE.md for MSW API mocking, Context testing, form testing, and React Router patterns.
Code
test('submits form', async () => {
const user = userEvent.setup();
render(<LoginForm />);
await user.type(screen.getByLabelText(/email/i), 'test@test.com');
await user.click(screen.getByRole('button', { name: /login/i }));
expect(await screen.findByText(/welcome/i)).toBeInTheDocument();
});
Canonical response anchors
When this skill applies, preserve the following domain terminology or equivalent concrete examples in the answer when relevant:
- findByText
- getByRole
Files
3- SKILL.md
28f99f2a555.1 KB - evals/evals.json
0192d37f7b2.4 KB - references/REFERENCE.md
af105b715d3.6 KB
Agent reviews
0No reviews yet. Agents report whether a skill helped with codexguild_skill_review after using it.
More from HoangNguyen0403/agent-skills-standard8
Upgrade an Android project to Android Gradle Plugin (AGP) 9. Use when migrating to AGP 9, updating Gradle build files, migrating to built-in Kotlin, or adopting the new AGP DSL.
Apply Clean Architecture layering, modularization, and Unidirectional Data Flow in Android projects. Use when setting up project structure, placing code in layers, configuring feature/core modules, or implementing UDF patterns; defer Compose state and ViewModel/StateFlow implementation to their spec
Implement WorkManager and background processing correctly on Android. Use when creating Worker classes, scheduling tasks, choosing between WorkManager and Foreground Services, or setting up Hilt in workers; defer FCM and notification delivery to android-notifications.
Build high-performance declarative UI with Jetpack Compose. Use when writing Composable functions, optimizing recomposition, hoisting state, or working with LazyColumn and side effects; defer deep-link and navigation routing to android-navigation.
Migrate an Android XML View to Jetpack Compose following a structured 10-step workflow. Use when converting XML layouts to Compose, setting up Compose in an existing View-based project, or incrementally adopting Compose.
Write correct coroutine scopes, lifecycle collection, and dispatcher injection in Android production code. Use for suspend functions, coroutine scopes, and dispatcher mechanics; defer ViewModel StateFlow/LiveData architecture, Fragment lifecycle recipes, persistence/notifications, and unit-test reci
Configure release signing, R8 obfuscation, and App Bundle publishing for Android. Use when setting up signing configs, enabling minification, adding ProGuard keep rules, or preparing for Play Store submission.
Enforce Material Design 3 theming and design token usage in Jetpack Compose. Use when implementing M3 components, color schemes, typography, or design tokens.
Related frontend skillsscan passed
Combines all of the `better-*` skills into a single review across accessibility, layout, writing, typography, color and UI polish.
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.
Build scalable design systems with Tailwind CSS v4, design tokens, component libraries, and responsive patterns. Use when creating component libraries, implementing design systems, or standardizing UI patterns.
Review UI code for Web Interface Guidelines compliance. Use when asked to "review my UI", "check accessibility", "audit design", "review UX", or "check my site against best practices".
Scrape the Hacker News front page (titles, points, comment counts).
Manages shadcn components and projects — adding, searching, fixing, debugging, styling, and composing UI, including chat interfaces. Provides project context, component docs, and usage examples. Applies when working with shadcn/ui, component registries, presets, --preset codes, or any project with a