我无法运行Jest测试,并且有一个非常模糊的错误消息.
我在StackOverflow上发现了一个类似的问题,我无法通过在node_module的react文件夹中添加jestSupport的建议来解决它.
我在StackOverflow上发现了一个类似的问题,我无法通过在node_module的react文件夹中添加jestSupport的建议来解决它.
问题参考:
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: 'testmcnameyname@gmail.com'}); }); };
有没有人遇到过这个问题,&有建议吗?
把它放在我的package.json中,与“脚本”处于同一级别,对我有用:
原文链接:https://www.f2er.com/react/300869.html"jest": { "unmockedModulePathPatterns": [ "react" ] }
我的测试文件顶部没有任何jest.dontMock语句.我只将jest.unmock用于测试模块.