以下代码是官方给出的演示
import { call, put, take } from 'redux-saga/effects'
import { expectSaga } from 'redux-saga-test-plan'
function * userSaga (api) {
const action = yield take('REQUEST_USER')
const user = yield call(api.fetchUser, action.payload)
yield put({ type: 'RECEIVE_USER', payload: user })
}
it('just works!', () => {
const api = {
fetchUser: id => ({ id, name: 'Tucker' })
}
return expectSaga(userSaga, api)
// Assert that the `put` will eventually happen.
.put({
type: 'RECEIVE_USER',
payload: { id: 42, name: 'Tucker' }
})
// Dispatch any actions that the saga will `take`.
.dispatch({ type: 'REQUEST_USER', payload: 42 })
// Start the test. Returns a Promise.
.run()
})
但是结果实际上是一个错误。
以下是版本信息:
"redux-saga": "^1.0.0-beta.0",
"redux-saga-test-plan": "^3.7.0"
帮助!
答案 0 :(得分:0)