Jest找不到模块FileName.css(映射为identity-obj-proxy)

时间:2017-09-08 01:29:03

标签: reactjs tdd jestjs

我一直在尝试为我的React项目设置测试环境,导入CSS文件时出现了意外令牌问题。我将moduleNameMapper添加到package.json来修复它,现在我正面临这个问题。 有谁知道我该怎么做才能解决这个问题?

> myProject@0.0.1 test C:\Users\admin\Documents\myApp
> jest

FAIL _tests_\Home.test.js
  ● Test suite failed to run

    Configuration error:

    Could not locate module react-datepicker/dist/react-datepicker-cssmodules.css (mapped as identity-obj-proxy)

    Please check:

    "moduleNameMapper": {
      "/^.+\.(css|less)$/": "identity-obj-proxy"
    },
    "resolver": undefined

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.894s
Ran all test suites.
npm ERR! Test failed.  See above for more details.

package.json

的jest部分
  "jest": {
    "transform": {
      "^.+\\.jsx?$": "babel-jest"
    },
    "moduleNameMapper": {
      "\\.(s?css|less)$": "identity-obj-proxy"
    }
  },

4 个答案:

答案 0 :(得分:14)

确保你的devDependencies

中有identity-obj-proxy
"devDependencies": {
  "identity-obj-proxy": "^3.0.0",
  ...
}

如果没有,请运行

npm install --save-dev identity-obj-proxy

答案 1 :(得分:1)

我们通过将Jest降级到20.0.4,更新到21.0.1并使用此错误打破我们的构建来修复此错误

答案 2 :(得分:1)

确保devDependencies列表中包含identity-obj-proxy npm包。

答案 3 :(得分:0)

就我而言,投诉是因为最近版本的jest决定强制执行文件扩展名,而我的<div id="pad"> <strong>start time:</strong> <span id="start"></span> <br/> <strong>event time:</strong> <span id="event"></span> <br/> <strong>difference:</strong> <span id="diff"></span> </div> <button id="reset">reset</button>配置缺少“ scss”

package.json