-
Notifications
You must be signed in to change notification settings - Fork 135
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
After migrating a React project to Vite+ using vp migrate, tests that use @testing-library/jest-dom/vitest fail with:
Error: Invalid Chai property: toBeInTheDocument
Root cause
@testing-library/jest-dom/vitest internally calls require('vitest').expect.extend(matchers) to register custom matchers. However, in Vite+, vitest is aliased to @voidzero-dev/vite-plus-test via npm overrides. The expect instance obtained by jest-dom through require('vitest') appears to be a different instance from the one actually used during test execution, so the matchers are never registered on the real expect.
Workaround
Manually importing matchers and extending expect from vite-plus/test works:
// setupTests.ts
// import '@testing-library/jest-dom/vitest'; // ← does NOT work
import * as matchers from '@testing-library/jest-dom/matchers';
import { expect } from 'vite-plus/test';
expect.extend(matchers);Reproduction
- Create a React project that uses
@testing-library/jest-domwithimport '@testing-library/jest-dom/vitest'insetupTests.ts - Run
vp migrate - Run
vp test run - All tests using jest-dom matchers (
toBeInTheDocument,toHaveTextContent, etc.) fail with "Invalid Chai property"
Steps to reproduce
vp migrateon an existing Vite + Vitest + React projectvp test run
System Info
vp v0.1.11
Local vite-plus:
vite-plus v0.1.11
Tools:
vite v8.0.0
rolldown v1.0.0-rc.9
vitest v4.1.0
oxfmt v0.40.0
oxlint v1.55.0
oxlint-tsgolint v0.16.0
tsdown v0.21.2
Environment:
Version 24.14.0
Source lts
Logs
Error: Invalid Chai property: toBeInTheDocument
❯ Object.proxyGetter [as get] node_modules/@voidzero-dev/vite-plus-test/dist/vendor/chai.mjs:1203:15
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
Type
Fields
Give feedbackPriority
None yet
Effort
None yet