Error running incrementAsync test
See original GitHub issueI’ve copied the test content, and it fails when I run it:
incrementAsync Saga test
/srv/http/redux-saga-beginner-tutorial/sagas.spec.js:16 var gen = (0, _sagas.incrementAsync)(); ^
TypeError: (0 , _sagas.incrementAsync) is not a function at Test.<anonymous> (/srv/http/redux-saga-beginner-tutorial/sagas.spec.js:8:15) at Test.bound [as _cb] (/srv/http/redux-saga-beginner-tutorial/node_modules/tape/lib/test.js:64:32) at Test.run (/srv/http/redux-saga-beginner-tutorial/node_modules/tape/lib/test.js:83:10) at Test.bound [as run] (/srv/http/redux-saga-beginner-tutorial/node_modules/tape/lib/test.js:64:32) at Immediate.next (/srv/http/redux-saga-beginner-tutorial/node_modules/tape/lib/results.js:71:15) at runCallback (timers.js:756:18) at tryOnImmediate (timers.js:717:5) at processImmediate [as _immediateCallback] (timers.js:697:5)
Reason for that is that we are not exporting the function, like:
export function* incrementAsync()
See, the tutorial took ride of the export directive when it introduced rootSaga() concept.
https://redux-saga.js.org/docs/introduction/BeginnerTutorial.html
import { delay } from 'redux-saga'
import { put, takeEvery, all } from 'redux-saga/effects'
function* incrementAsync() {
yield delay(1000)
yield put({ type: 'INCREMENT' })
}
function* watchIncrementAsync() {
yield takeEvery('INCREMENT_ASYNC', incrementAsync)
}
// notice how we now only export the rootSaga
// single entry point to start all Sagas at once
export default function* rootSaga() {
yield all([
helloSaga(),
watchIncrementAsync()
])
}
So, if you guys wanna test the function, export it.
export function* incrementAsync() {
yield delay(1000)
yield put({ type: 'INCREMENT' })
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:17
- Comments:5
Top GitHub Comments
Please check if you export delay also.
i missed it initially too but on https://redux-saga.js.org/docs/introduction/BeginnerTutorial.html the code right after “Well, redux-saga provides a way to make the above statement possible. Instead of calling delay(1000) directly inside incrementAsync, we’ll call it indirectly:” that changes the delay invocation to using call also adds export to incrementAsync.