Jest找不到模块' setupDevtools'来自' setup.js'

时间:2017-12-12 21:21:00

标签: javascript reactjs react-native jestjs

Jest的新手作为我的React / Redux应用程序的测试套件,由于此错误困扰我的应用程序,我无法运行actions测试:

  

测试套件无法运行

     

无法找到模块' setupDevtools'来自' setup.js'

     

在Resolver.resolveModule(node_modules / jest-resolve / build / index.js:191:17)

     

at Object。 (node_modules /反应天然/笑话/ setup.js:30:1)

从我的测试文件中删除所有内容会产生相同的错误。这是我的Jest配置:

"jest": {
    "verbose": true,
    "preset": "jest-react-native",
    "roots": [
      "<rootDir>/src/actions/_tests_"
    ]
  }

以下是我的依赖项:

  "dependencies": {
    "dotenv": "^4.0.0",
    "fhirclient": "^0.1.12",
    "full-age-calculator": "0.0.4",
    "prop-types": "^15.6.0",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-redux": "^5.0.6",
    "redux": "^3.7.2",
    "redux-thunk": "^2.2.0",
    "verror": "^1.10.0"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-env": "^1.6.1",
    "babel-preset-react": "^6.24.1",
    "css-loader": "^0.28.7",
    "eslint": "^4.12.1",
    "eslint-config-cerner": "^1.0.0",
    "eslint-plugin-import": "^2.8.0",
    "eslint-plugin-jsx-a11y": "^5.1.1",
    "eslint-plugin-react": "^7.5.1",
    "html-webpack-plugin": "^2.30.1",
    "jest": "^21.2.1",
    "jest-react-native": "^18.0.0",
    "node-sass": "^4.7.2",
    "react-native": "^0.51.0",
    "sass-loader": "^6.0.6",
    "style-loader": "^0.19.0",
    "webpack": "^3.10.0",
    "webpack-dev-server": "^2.9.5"
  },

我尝试了this Github issue page的一些建议,这些建议没有解决我的问题。

1 个答案:

答案 0 :(得分:0)

我今天重新开始并解决了我自己的问题。事实证明,Babel有documentation,它具体解释了如何设置Jest。总之,这就是我所做的:

安装NPM模块

npm install --save-dev babel-jest
npm install --save-dev babel-preset-env

或使用一个命令:

npm install i -d babel-jest babel-preset-env

创建.babelrc配置文件

{
  "presets": ["env"]
}

修改package.json

{
  "scripts": {
    "test": "jest"
  },
  "jest": {
    "transform": {
      "^.+\\.jsx?$": "babel-jest"
    }
  }
}

以下是env preset部分需要<div class="container"> <h1> Your todos </h1> <input type="text" id="todo" placeholder="Add a new todo and hit enter" onkeydown="store(this)"> <div class="todos"> <ul id="demo"></ul> </div> </div> <script> var list = document.getElementById('demo'); function store(ele){ if(event.keyCode==13){ changeText(); } } function changeText() { var data = document.getElementById('todo').value; var d = new Date(); if(data!='') { var entry = document.createElement('li'); var dates = document.createElement("div"); dates.appendChild(document.createTextNode(d.toDateString())); dates.className = "myClass"; entry.appendChild(document.createTextNode(data)); entry.onclick=struck(this); entry.appendChild((dates)); list.appendChild(entry); } } function struck(ele) { ele.style = "text-decoration:line-through; list-style-type:none"; } </script> 配置的原因。快乐的编码!