vitest-dom provides custom Vitest matchers to assert on the state of the DOM, directly forked from `@testing-library/jest-dom`. It shares the same implementation and API, making it a drop-in replacement for existing tests transitioning from Jest to Vitest. The current stable version is `0.1.1`, indicating it's still in its early development stages (pre-1.0.0), which implies that breaking changes could occur in minor or even patch releases before a stable major version is reached. Its primary differentiation is its dedicated support for Vitest environments and types, avoiding potential clashes when trying to use `@testing-library/jest-dom` directly with Vitest.
npm install vitest-domVerified import paths — ran on the pinned version, not inferred.
Demonstrates installation, configuration with `setupFiles` in `vitest.config.ts`, and basic usage of `vitest-dom` matchers in a component test file.
Always use `vitest-dom` when working with Vitest to ensure correct types and integrations. Only use `@testing-library/jest-dom` with Jest.
Pin your dependency to an exact version (`~0.1.x`) and thoroughly review changelogs when upgrading, especially before `1.0.0` is released.
Ensure your `vitest.config.js` includes `test: { environment: 'jsdom' }` or `test: { environment: 'happy-dom' }`. Refer to Vitest documentation for environment configuration.For automatic type inclusion, use `import 'vitest-dom/extend-expect';`. Otherwise, add `/// <reference types="vitest-dom/extend-expect" />` to your setup file or `"types": ["vitest-dom/extend-expect"]` to `compilerOptions` in `tsconfig.json`.
Ensure `vitest-dom/extend-expect` is imported in a `setupFiles` configured in `vitest.config.js` (and that the setup file is `.ts` for TypeScript). If manually extending, verify `expect.extend(matchers)` is called and types are referenced correctly.
Add `test: { environment: 'jsdom' }` or `test: { environment: 'happy-dom' }` to your `vitest.config.js`.Make sure `import { expect } from 'vitest';` is present before calling `expect.extend()`, or use the `import 'vitest-dom/extend-expect';` convenience import.