使用Enzyme和Jest测试具有实质性UI的React组件

时间:2018-10-29 22:29:46

标签: testing

我的组件从react组件中的材料ui导入以下内容

import Dialog from '@material-ui/core/Dialog';
import DialogContent from '@material-ui/core/DialogContent';
import { withStyles } from '@material-ui/core/styles';

虽然我用酶和玩笑编写了测试用例,但在运行测试用例时却看到以下错误,这是由于材质ui对话框以及如果需要使用该如何模拟我该怎么办。

测试套件无法运行:

      TypeError: (0 , _ponyfill2.default) is not a function

     1 | import './login.css';
     2 | import React, { Component } from 'react';
     > 3 | import Dialog from '@material-ui/core/Dialog';
         | ^
     4 | import DialogContent from '@material-ui/core/DialogContent';
     5 | import { withStyles } from '@material-ui/core/styles';
     6 | import { Redirect } from "react-router-dom";

      at Object.<anonymous> (node_modules/jss/node_modules/symbol- 
      observable/lib/index.js:28:40)
     at Object.<anonymous> (node_modules/jss/lib/utils/isObservable.js:7:25)
     at Object.<anonymous> (node_modules/jss/lib/utils/cloneStyle.js:11:21)
     at Object.<anonymous> (node_modules/jss/lib/utils/createRule.js:16:19)
     at Object.<anonymous> (node_modules/jss/lib/RuleList.js:11:19)  

我的package.json:

"babel-cli": "6.26.0",
"babel-core": "6.26.0",
"babel-eslint": "8.2.6",
"babel-jest": "^23.4.2",
"babel-polyfill": "^6.26.0",
"enzyme": "^3.4.4",
"enzyme-adapter-react-16": "^1.2.0",
"jest": "^23.5.0",   

有人可以让我知道为什么会发生错误吗?

0 个答案:

没有答案