Jest遇到意外令牌,因为尝试导入Jest无法解析的文件

时间:2019-08-01 07:53:09

标签: reactjs testing react-redux jestjs enzyme

PS E:\ react \ Code \ UI>纱线测试 纱线运行v1.17.3 开玩笑  失败src / App.test.js   ●测试套件无法运行

// Assuming you've configured CORS correctly on your server:
fetch('https://some.microservice.myapp.com/getdata')
  .then(function(response) {
    return response.json();
  })
  .then(function(result) {
    console.log(result);
  });

// Assuming you are using an application gateway:
fetch('https://myapp.com/some/microservice/getdata')
  .then(function(response) {
    return response.json();
  })
  .then(function(result) {
    console.log(result);
  });

测试套件:1个失败,总共1个 测试:总计0 快照:共0个 时间:3.592秒 运行所有测试套件。 错误命令失败,退出代码为1。 信息请访问https://yarnpkg.com/en/docs/cli/run,以获取有关此命令的文档。

1 个答案:

答案 0 :(得分:1)

模拟您的CSS文件

Jest不知道如何处理CSS文件。您需要在玩笑配置中处理它们。 here确实有很好的信息。

但是从本质上讲,您需要在玩笑的配置中添加类似的内容

// package.json (for CSS Modules)
{
  "jest": {
    "moduleNameMapper": {
      "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
      "\\.(css|less)$": "identity-obj-proxy"
    }
  }
}
相关问题