@@ -166,3 +166,72 @@ This works because:
1661662 . ` processCSSProp() ` explicitly handles both forms in its switch statement
167167
168168** When you see ` as any ` in tests:** This usually indicates a type mismatch. Check if the prop should be ` CSSProps['css'] ` instead of ` CSSProps ` .
169+
170+ ### Testing Vanilla Extract Components
171+
172+ ** REQUIRED:** Every vanilla-extract component MUST have a corresponding ` .vanilla.test.tsx ` file with comprehensive tests.
173+
174+ ** Test File Naming:**
175+
176+ - Vanilla-extract components: ` ComponentName.vanilla.test.tsx `
177+ - Stitches components: ` ComponentName.test.tsx `
178+
179+ ** Required Test Coverage:**
180+
181+ - Basic rendering and element types
182+ - Custom className support
183+ - All variant props (size, weight, variant, gradient, transform, noWrap, etc.)
184+ - Custom styling (CSS prop and style prop)
185+ - Style merging behavior
186+ - Polymorphic rendering (if component supports ` as ` prop)
187+ - Ref forwarding
188+ - HTML attribute pass-through
189+ - Accessibility testing with jest-axe
190+ - Theme support (light/dark and different primary colors)
191+
192+ ** Testing Pattern:**
193+
194+ ``` tsx
195+ import { render } from ' @testing-library/react' ;
196+ import { axe } from ' jest-axe' ;
197+ import React from ' react' ;
198+
199+ import { VanillaExtractThemeProvider } from ' ../../styles/themeContext' ;
200+ import { ComponentVanilla } from ' ./Component.vanilla' ;
201+
202+ describe (' ComponentVanilla' , () => {
203+ const renderWithTheme = (ui : React .ReactElement ) => {
204+ return render (<VanillaExtractThemeProvider >{ ui } </VanillaExtractThemeProvider >);
205+ };
206+
207+ it (' should render correctly' , () => {
208+ const { container } = renderWithTheme (<ComponentVanilla >Content</ComponentVanilla >);
209+ expect (container .firstChild ).toBeInTheDocument ();
210+ });
211+
212+ it (' should have no accessibility violations' , async () => {
213+ const { container } = renderWithTheme (<ComponentVanilla >Content</ComponentVanilla >);
214+ const results = await axe (container );
215+ expect (results ).toHaveNoViolations ();
216+ });
217+
218+ // Use unmount() in loops to prevent "multiple elements found" errors
219+ it (' should apply size variants' , () => {
220+ const sizes = [' small' , ' medium' , ' large' ] as const ;
221+ sizes .forEach ((size ) => {
222+ const { container, unmount } = renderWithTheme (
223+ <ComponentVanilla size = { size } >Content</ComponentVanilla >,
224+ );
225+ expect (container .firstChild ).toBeInTheDocument ();
226+ unmount ();
227+ });
228+ });
229+ });
230+ ```
231+
232+ ** Important Notes:**
233+
234+ - Always wrap components in ` VanillaExtractThemeProvider ` for tests
235+ - Use ` unmount() ` in forEach loops to prevent DOM element accumulation
236+ - For Radix-based components, use the correct role (e.g., ` role="radio" ` for ButtonSwitch items, not ` role="button" ` )
237+ - Reference the ` Input.vanilla.test.tsx ` file as the gold standard for test patterns
0 commit comments