简体   繁体   English

酶修饰的组件TypeError:无法读取未定义的属性'contextTypes'

[英]Enzyme decorated components TypeError: Cannot read property 'contextTypes' of undefined

I am testing a component decorated with JSCC with enzyme and jest, but I receive the following error: 我正在用酶和玩笑测试用JSCC装饰的组件,但是收到以下错误:

TypeError: Cannot read property 'contextTypes' of undefined TypeError:无法读取未定义的属性“ contextTypes”

How to test this styled component? 如何测试这个样式化的组件?

 import React from 'react' import { shallow } from 'enzyme' import { PdfViewer } from './PdfViewer' const baseProps = { location: 'url', defaultPage: 1, classes: {}, handlePageChanged: () => {}, } describe('<PdfViewer />', () => { it('should work', () => { const wrapper = shallow(<PdfViewer {...baseProps} />) console.log(wrapper.debug()) }) }) 

The component is decorated as: 该组件装饰为:

 class PdfViewer extends React.Component{} ../ export default withStyles(styleSheet)(PdfViewer) 

 import { muiTheme } from 'material-ui/styles' const wrapper = shallow(<PdfViewer {...baseProps} />, { context: { muiTheme } }) 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法读取未定义的反应路由器测试的属性“ contextTypes” - Cannot read property 'contextTypes' of undefined, react-router testing TypeError:无法读取未定义的酶和摩卡反应测试的属性“ map” - TypeError: Cannot read property 'map' of undefined react test with enzyme and mocha 类型错误:无法读取未定义的笑话酶的属性“值” - TypeError: Cannot read property 'value' of undefined jest enzyme TypeError:无法读取未定义的属性“创建”(材料 UI/酶) - TypeError: Cannot read property 'create' of undefined (Material UI/enzyme) 使用酶进行反应测试TypeError:无法读取未定义的属性“state” - React test with enzyme TypeError: Cannot read property 'state' of undefined 酶装载API问题:TypeError:无法读取未定义的属性“ find” - Enzyme mount API issue: TypeError: Cannot read property 'find' of undefined 反应,酶:无法读取未定义的属性“历史” - React, Enzyme : Cannot read property 'history' of undefined 类型错误:无法读取未定义功能组件的属性“类型” - TypeError: Cannot read property 'type' of undefined functional components TypeError:无法读取组件上未定义的属性“值”(ReactJS表单) - TypeError: Cannot read property 'value' of undefined on components (ReactJS forms) 类型错误:在 React Enzyme 中加载脚本时无法读取未定义的属性“src” - TypeError: Cannot read property 'src' of undefined when loading script in React Enzyme
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM