【问题标题】:Jest-dom unable to find module inside of its folder in node_modulesJest-dom 无法在 node_modules 的文件夹中找到模块
【发布时间】:2021-09-04 09:37:39
【问题描述】:

当我添加到我的 test-setup.js import "@testing-library/jest-dom"; 运行任何测试时,Jest 会抛出这个错误。如果我删除导入一切正常。尝试直接在测试文件中添加导入,没有成功。

这是 test-setup.js 的样子:

import '@testing-library/jest-dom';
import { server } from 'mocks/server';

beforeAll(() => server.listen());

afterEach(() => server.resetHandlers());

afterAll(() => server.close());

错误:

Cannot find module 'css' from 'node_modules/@testing-library/jest-dom/dist/utils.js'

Require stack:
 node_modules/@testing-library/jest-dom/dist/utils.js
 node_modules/@testing-library/jest-dom/dist/to-be-in-the-dom.js
 node_modules/@testing-library/jest-dom/dist/matchers.js
 node_modules/@testing-library/jest-dom/dist/extend-expect.js
 node_modules/@testing-library/jest-dom/extend-expect.js
 test-setup.js

at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:311:11)
at Object.<anonymous> (node_modules/@testing-library/jest-dom/dist/utils.js:22:12)

【问题讨论】:

    标签: reactjs jestjs react-testing-library testing-library jest-dom


    【解决方案1】:

    尝试单独安装

    npm install -D jest-dom
    # or yarn
    yarn add --dev jest-dom
    

    【讨论】:

      猜你喜欢
      • 2019-04-27
      • 1970-01-01
      • 1970-01-01
      • 2021-08-27
      • 2020-05-18
      • 2022-11-22
      • 2015-04-16
      • 2019-06-08
      • 2023-01-13
      相关资源
      最近更新 更多