testing-library / react-testing-library

🐐 Simple and complete React DOM testing utilities that encourage good testing practices.

Home Page:https://testing-library.com/react

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

when running unit tests Cannot find "swiper/css"

mrfour44 opened this issue · comments

  • @testing-library/react version: 12.1.5
  • Testing Framework and version: @testing-library/jest-dom 5.16.4 @testing-library/react-hooks 7.0.2 @testing-library/user-event 13.5.0
  • DOM Environment:Jest-27.5.1

Relevant code or config:

"jest": {
    "transformIgnorePatterns": [
      "node_modules/(?!echarts)/"
    ],
    "collectCoverageFrom": [
      "src/**/*.{js,jsx,ts,tsx}",
      "!src/bootstrap.tsx",
      "!src/setupProxy.js",
      "!src/generated/**",
      "!src/**/index.{js,jsx,ts,tsx}",
      "!src/**/*Api.ts",
      "!src/modules/app-fwk/route/all-screen-data.tsx",
      "!src/modules/test/**",
      "!src/spa-plugin/**",
      "!src/api/**",
      "!src/config/**",
      "!src/routers/**"
    ],
    "moduleNameMapper": {
      "\\.(css|less)$": "identity-obj-proxy"
    }
  }

What you did:

Using swiper in React, you can npm run start, the swiper version is 8.2.2
but when running unit tests, error "Cannot find module 'swiper/css'"
The unit tests used react-testing-library. Jest has configured moduleNameMapper as "identity-obj-proxy".

What happened:

"Cannot find module 'swiper/css'"

Reproduction:

Problem description:

Suggested solution:

Hi @mrfour44, thanks for opening this one.
This doesn't seem related to testing-library because the exception you're getting seems like a configuration issue.
I recommend trying our discord server for help or opening a question in stackoverflow.
Thanks again.

@mrfour44 Hi I am facing the same issue right now,

did you find a solution?