New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vitest-dom

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vitest-dom

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

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
49K
decreased by-2.84%
Maintainers
1
Weekly downloads
 
Created
Source

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 the matchers from vitest-dom/matchers once (perferably in your tests setup file), then pass them to Vitest's expect.extend method:

// vitest-setup.js
import * as matchers from "vitest-dom/matchers";
import { expect } from "vitest";
expect.extend(matchers);

// or:
import "vitest-dom/extend-expect";

// In vitest.config.js, add the following
export default defineConfig({
  test: {
    setupFiles: ["vitest-setup.js"],
  },
});

With TypeScript

If you're using TypeScript, make sure your setup file has a .ts extension to include the necessary types.

If you import from vitest-dom/extend-expect to run expect.extend for you, you will get TypeScript support automatically.

// vitest-setup.ts
import "vitest-dom/extend-expect";

If you want to run extend.expect yourself, you will need to include the type defintions either with a /// <reference /> directive or including the type in your compilerOptions:

  1. In your test file via a reference directive:
    /// <reference types="vitest-dom/extend-expect" />
    
  2. In your tsconfig.json via the types compiler option:
    {
      "compilerOptions": {
        "types": ["vitest-dom/extend-expect"]
      }
    }
    

FAQs

Package last updated on 16 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc