testing-library / jest-dom

:owl: Custom jest matchers to test the state of the DOM

Home Page:https://testing-library.com/docs/ecosystem-jest-dom

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in --experimental-vm-modules, when resolveStubModuleName(), jest-dom cause wrong from params

jaredhan418 opened this issue · comments

  • @testing-library/jest-dom version: 6.1.3
  • node version: 18.17
  • jest (or vitest) version: 29.7.0
  • npm (or yarn) version: 10.0

Relevant code or config:

jest.unstable_mockModule("./xxxx-list/index.js", () => ({
  XXXXList: jest.fn(() => null),
}));

What you did:

Normal test case, crash when upgrade to 6.1.3

What happened:

截屏2023-09-20 18 25 39

Reproduction:

Create a test file with

jest.unstable_mockModule("./xxxx-list/index.js", () => ({
  XXXXList: jest.fn(() => null),
}));

Start jest with node --experimental-vm-modules node_modules/jest/bin/jest.js
then jest will try to execute resolveStubModuleName(from, moduleName) at node_modules/jest-resolve/build/resolver.js

without jest-dom the function looks like below
截屏2023-09-20 18 13 09

after I import import "@testing-library/jest-dom/jest-globals"; in setup file.

the from param will become @testing-library/jest-dom/dist/jest-globals.mjs as screenshot below
截屏2023-09-20 18 11 51

Problem description:

Suggested solution: