开玩笑的问题-ReactElement.js:无法获取模拟元数据 [英] Jest issue - ReactElement.js: Failed to get mock metadata

查看:175
本文介绍了开玩笑的问题-ReactElement.js:无法获取模拟元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的测试

I've a very simple test

/** @jsx React.DOM */
var store = require('../simpleStore');
var TestUtils = require('react/addons').addons.TestUtils;

describe("my tests",function(){
  it('simple test',function(){
     var x=10,
        y=20;
     expect(x).not.toBe(y);
  })
})

只要我不需要TestUtils,测试就可以正常工作. 添加任何node_module引用的那一刻,我开始看到以下错误

Test works fine as long as I dont require TestUtils. The moment I add any node_module reference, I start seeing below error

Using Jest CLI v0.8.0, jasmine1
FAIL  build/stores/__tests__/simple-test.js

● Runtime Error

Error: ../stores/__tests__/simple-test.js:
../../node_modules/react/addons.js:
../../node_modules/react/lib/ReactWithAddons.js:
../../node_modules/react/lib/LinkedStateMixin.js:
../../node_modules/react/lib/ReactLink.js:
../../node_modules/react/lib/React.js:
../../node_modules/react/lib/ReactDOM.js:
../../node_modules/react/lib/ReactDOMTextComponent.js:
../../node_modules/react/lib/ReactComponentBrowserEnvironment.js:
../../node_modules/react/lib/ReactDOMIDOperations.js:
../../node_modules/react/lib/ReactMount.js:
../../node_modules/react/lib/ReactElement.js: Failed to get mock metadata:
../../node_modules/react/lib/canDefineProperty.js
npm ERR! Test failed.  See above for more details.

我确定很多人都在开玩笑,我想念一些愚蠢的东西..想出任何办法解决这个问题吗?

I'm sure a lot of people are using jest and I'm missing something silly..appreaciate any ideas to fix this issue?

推荐答案

尝试禁用对响应的模拟-在package.json的jset配置中:

Try to disable mocking for react - in your jset configuraction in package.json:

"unmockedModulePathPatterns": [
  "<rootDir>/node_modules/react",
  "<rootDir>/node_modules/fbjs"
]

这篇关于开玩笑的问题-ReactElement.js:无法获取模拟元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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