我无法运行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中,与“脚本”处于同一级别,对我有用:
"jest": { "unmockedModulePathPatterns": [ "react" ] }
我的测试文件顶部没有任何jest.dontMock语句.我只将jest.unmock用于测试模块.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。