我看到这个错误:
✖ should dispatch profileAction
PhantomJS 1.9.8 (Linux 0.0.0)
TypeError: 'undefined' is not a function (evaluating '_Header2.default.__Rewire__('profileAction', function (a) {
a();
})')
at /home/piousbox/Dropbox/projects/colombia_tailors_react/app/app.tests.js:74904 <- webpack:///app/components/App/__tests__/Header-test.jsx:23:53
我的测试如下所示:
it('should dispatch profileAction', (done) => {
Header.__Rewire__('profileAction', (a) => { a() })
let r = ReactTestUtils.renderIntoDocument(
<Provider store={store}>
<Header router={{location:{}}} />
</Provider>)
let elem = ReactDOM.findDOMNode(r)
})
我的生产代码如下所示:
import { profileAction } from '../../actions/profileActions'
profileAction // eslint-disable-line no-unused-expressions
class Header extends React.Component {
constructor(props) {
super(props)
props.dispatch(profileAction())
}
render () { ... }
}
我究竟做错了什么?我希望断言在安装组件 Header 时调用了 profileAction() 。