使用Jest和嵌套的Redux连接的组件进行React单元测试时始终不变

时间:2018-11-01 12:57:24

标签: reactjs redux frontend jestjs

我正在测试一个React组件,其中包含一个连接的(Redux)导出的组件。开玩笑,我的测试文件中只有

import React from 'react'
import { shallow } from 'enzyme'

import MyPage from './../my-page.js'

运行测试时,控制台中会提示以下错误

Test suite failed to run

Invariant Violation: You must pass a component to the function returned by 
connect. Instead received undefined

正在测试的MyPage组件如下

import React from 'react'
import { MyContainer } from 'recharge/containers'

const MyPage = () => (
  <section className="my-page">
    <h2 className="page-title">Some text</h2>
    <MyContainer />
  </section>
)

export default MyPage

嵌套连接的组件MyContainer是

import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'

import { Creators as OrderActions } from 'store/ducks/order'

import { My } from 'recharge/components'

const mapStateToProps = state => ({
  my: state.order.my,
  order: state.order.order
})

const mapDispatchToProps = (dispatch) => bindActionCreators(OrderActions, dispatch)

export default connect(mapStateToProps, mapDispatchToProps)(My)

0 个答案:

没有答案