【发布时间】:2018-05-25 04:22:20
【问题描述】:
我有一个创建动作的函数
export function dispatchAction (type, payload) {
return dispatch => {
dispatch({type: type, payload: payload})
}
}
我正在为它写测试
import configureMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'
import * as actions from './actions
const mockStore = configureMockStore([thunk])
const store = mockStore({})
describe('dispatch action', () => {
it('should return action based on type and payload', () => {
const type = 'TEST'
const payload = 'payload'
return store.dispatch(actions.dispatchAction(type, payload)).then(()
=> {
expect(store.getActions())
.toEqual({type, payload})
})
})
})
但我收到Cannot read property 'then' of undefined 的错误。
【问题讨论】:
-
什么是
mockStore。那个函数返回什么? -
更新了新代码
标签: reactjs redux enzyme jestjs redux-thunk