我的测试非常简单
/** @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引用的那一刻,我开始看到下面的错误
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.
我确信很多人都在使用开玩笑而且我错过了一些愚蠢的东西......是否有任何解决这个问题的想法?
答案 0 :(得分:5)
尝试禁用mock的反应 - 在package.json中的jset配置中:
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/react",
"<rootDir>/node_modules/fbjs"
]