我無法運行Jest測試並且有非常模糊的錯誤消息。 我在StackOverflow上發現了一個類似的問題,我無法用他們在node_module的react文件夾中添加jestSupport的建議來解決它。運行時錯誤運行Jest:在React中
問題引用: How to use Jest with React Native
__tests__/profile-test.js
● Runtime Error
TypeError: Cannot read property 'DEFINE_MANY' of undefined
//段從的package.json
"scripts": {
"test": "jest"
},
"jest": {
"scriptPreprocessor": "<rootDir>/node_modules/babel-jest"
},
//測試文件
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import Profile from '../components/profile';
jest.setMock('react', {}); // put this in after reading a troubleshooting article
//jest.autoMockOff(Profile);
describe('Profile'),() => {
it("renders a form containing user information", function() {
let Profile = TestUtils.renderIntoDocument(<Profile/>);
let renderedDOM =() => React.findDOMNode(Profile);
expect(renderedDOM.tagName).toBe('div');
expect(renderedDOM.classList).toEqual(['value', 'image', 'btn btn-primary', 'btn btn-danger' ]);
var children = renderedDOM.querySelectorAll('fieldConfig.type'); //created a custom
expect(children.length).toBe(3);
expect(children[0]).toEqual({name: 'test mc nameyname', email: '[email protected]'});
});
};
有沒有人遇到這樣的問題,&有建議嗎?
您是否找到解決方案? – inquisitive
對不起,我沒有。在與同事交談後,我決定明確地向Mocha,Chai和Enzyme轉交錯誤消息。 –