我尝试将我的组件包装到使用Provider进行测试,并使用react-test-renderer renderer.create()
对其进行深度渲染。在这种情况下,mapStateToProps可以正常工作,但我没有得到mapDispatchToProps的预期结果。这里测试的组件呈现其他连接组件。
我的mapDispatchToProps看起来像
/* @flow */
import { bindActionCreators } from 'redux';
import type { Dispatch } from './types';
import * as actions from './actions';
export default (dispatch: Dispatch, ownProps: Object): Object => ({
actions: bindActionCreators(actions, dispatch),
});
此处返回的actions
的值为undefined
。
store.js
import { applyMiddleware, compose, createStore } from 'redux';
import { autoRehydrate } from 'redux-persist';
import thunk from 'redux-thunk';
import rootReducer from './reducers';
import { REHYDRATE } from 'redux-persist/constants';
const store = compose(autoRehydrate(), applyMiddleware(thunk, createActionBuffer(REHYDRATE)))(createStore)(rootReducer);
导出默认商店;