Jest issue - ReactElement.js: Failed to get mock metadata

谁都会走 提交于 2019-12-23 12:15:41

问题


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);
  })
})

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?


回答1:


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

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


来源:https://stackoverflow.com/questions/33965690/jest-issue-reactelement-js-failed-to-get-mock-metadata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!