Skip to content

Commit 417be71

Browse files
docs: update testing documentation (#21985)
Co-authored-by: Andrew Henry <[email protected]> Resolves #21548
1 parent cff3c37 commit 417be71

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

packages/docs/src/pages/en/getting-started/unit-testing.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,58 @@ test('displays message', () => {
103103
expect(wrapper.text()).toContain('Components')
104104
})
105105
```
106+
107+
## Testing Vuetify Components
108+
109+
When testing Vuetify components, we recommend running tests in a real browser environment instead of `jsdom`.
110+
111+
### Recommended Test Runners
112+
113+
* [Vitest (browser mode)](https://vitest.dev/guide/browser/) – Fast, Vite-native test runner with browser support.
114+
* [Playwright](https://playwright.dev/) – End-to-end testing in actual browsers.
115+
* [Cypress](https://www.cypress.io/) – Great for integration and E2E tests.
116+
117+
### Rendering with Vuetify
118+
119+
To properly render Vuetify components in tests, create a Vuetify instance and pass it to the test renderer. You don’t need to mock transitions or other internals.
120+
121+
```ts { resource="vuetify/packages/vuetify/test/index.ts" }
122+
export function render<C> (
123+
component: C,
124+
options?: RenderOptions<C> | null,
125+
vuetifyOptions?: VuetifyOptions
126+
): RenderResult {
127+
const vuetify = createVuetify(mergeDeep({ icons: { aliases } }, vuetifyOptions))
128+
129+
const defaultOptions = {
130+
global: {
131+
stubs: {
132+
transition: false,
133+
'transition-group': false,
134+
},
135+
plugins: [vuetify],
136+
},
137+
}
138+
139+
const mountOptions = mergeDeep(defaultOptions, options!, (a, b) => a.concat(b))
140+
141+
return _render(component, mountOptions)
142+
}
143+
```
144+
145+
### Using `data-testid`
146+
147+
For reliable queries in tests, use `data-testid` attributes in your components:
148+
149+
```vue
150+
<v-btn data-testid="submit-btn">Submit</v-btn>
151+
```
152+
153+
```ts
154+
const { getByTestId } = render(MyComponent)
155+
expect(getByTestId('submit-btn')).toBeInTheDocument()
156+
```
157+
158+
### Accessibility Considerations
159+
160+
Tests should respect user accessibility preferences. Configure [prefers-reduced-motion](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion) when testing animations to avoid flakiness and ensure accessibility compliance.

0 commit comments

Comments
 (0)