单元测试 – 运行时错误运行Jest:在React中

我无法运行Jest测试,并且有一个非常模糊的错误消息.
我在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用于测试模块.

相关文章

react 中的高阶组件主要是对于 hooks 之前的类组件来说的,如...
我们上一节了解了组件的更新机制,但是只是停留在表层上,例...
我们上一节了解了 react 的虚拟 dom 的格式,如何把虚拟 dom...
react 本身提供了克隆组件的方法,但是平时开发中可能很少使...
mobx 是一个简单可扩展的状态管理库,中文官网链接。小编在接...
我们在平常的开发中不可避免的会有很多列表渲染逻辑,在 pc ...