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

时间:2017-10-21 21:33:55

标签: javascript enzyme jest

我正在使用酶和jest测试用JSCC修饰的组件,但是我收到以下错误:

  

TypeError:无法读取属性' contextTypes'未定义的

如何测试这个样式组件?



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())
  })
})
&#13;
&#13;
&#13;

组件装饰为:

&#13;
&#13;
class PdfViewer extends React.Component{}
../
export default withStyles(styleSheet)(PdfViewer)
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

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