我正在用酶和玩笑测试用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())
  })
})





该组件装饰为:



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

最佳答案

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

09-17 11:38