Skip to content

Custom Vitest matchers to test the state of the DOM, forked from jest-dom.

License

Notifications You must be signed in to change notification settings

Kamahl19/vitest-dom

Repository files navigation

vitest-dom

Custom Vitest matchers to test the state of the DOM


version MIT License

Watch on GitHub

This library is a fork of @testing-library/jest-dom. It shares that library's implementation and API. It is intended to make it easier to include its matchers without clashes between Vitest and Jest's environment or types.

See the README for the original package for usage details.

Installation

This module should be installed as one of your project's devDependencies:

# with npm
npm install --save-dev vitest-dom
# yarn
yarn add --dev vitest-dom
# pnpm
pnpm add --dev vitest-dom

Usage

Import vitest-dom once (for instance in your tests setup file) and you're good to go:

// In your own vitest-setup.js (or any other name)
import "vitest-dom/extend-expect";

// In vitest.config.js add (if you haven't already)
export default defineConfig({
  test: {
    setupFiles: ["vitest-setup.js"],
  },
});

With TypeScript

If you're using TypeScript, make sure your setup file is a .ts and not a .js to include the necessary types.

You will also need to include your setup file in your tsconfig.json if you haven't already:

  // In tsconfig.json
  "include": [
    // ...
    "./vitest-setup.ts"
  ],

About

Custom Vitest matchers to test the state of the DOM, forked from jest-dom.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 75.9%
  • TypeScript 24.1%