开玩笑的React示例 [英] Jest React Example

查看:195
本文介绍了开玩笑的React示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 Jest React教程中运行React示例.收到错误

I am trying to run the React Example from the Jest React tutorial but I am receiving errors

λ npm test                                          

> ...                           
> jest                                              

Found 1 matching tests...                           
 FAIL  __tests__\CheckboxWithLabel-test.js (0.551s) 
npm ERR! Test failed.  See above for more details.  
npm ERR! not ok code 0   

我几乎直接从示例中复制了代码. package.json如下:

I have pretty much copied the code directly from the example. The package.json is as follows:

{
  "dependencies": {
    "react": "*",
    "react-tools": "*"
  },
  "scripts":{
    "test": "jest"
  },
  "jest": {
    "scriptPreprocessor": "<rootDir>/preprocessor.js",
    "unmockedModulePathPatterns": [
      "<rootDir>/node_modules/react"
    ]
  },
  "devDependencies": {
    "jest-cli": "~0.1.17"
  }
}

关于如何解决这些错误并成功运行示例测试的任何想法?我很可能会漏掉一个(或多个)重要细节,但不能完全确定是什么.哦,这是有什么用,如果有影响,我可以在Windows上运行.我真的很想对我的react组件进行一些测试(那里也有一些麻烦,所以从基本示例开始)-任何帮助将不胜感激:)

Any thoughts on what I can do to resolve these errors and run the example test successfully? It's very possible I'm missing an important detail (or details) but not entirely sure what. Oh and for what it's worth, I'm running this on Windows if that impacts this. I would really like to get some tests on my react components (was having some trouble there too so started with the basic examples) -- any help would be appreciated :)

推荐答案

我创建了问题在他们的github页面上.等待找出它是否实际上是与Windows相关的问题

I created an issue on their github page. Waiting to find out if it is actually a windows related issue

与此同时,最终只需指定模块名称而不是相对路径即可使它工作

In the meantime, eventually got it working by just specifying the name of the module rather than the relative path

   "unmockedModulePathPatterns": ["react"]

这篇关于开玩笑的React示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆