加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 20:45:12 所属栏目:百科 来源:网络整理
导读:我无法运行Jest测试,并且有一个非常模糊的错误消息. 我在StackOverflow上发现了一个类似的问题,我无法通过在node_module的react文件夹中添加jestSupport的建议来解决它. 问题参考: How to use Jest with React Native __tests__/profile-test.js● Runtime
我无法运行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用于测试模块.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读