redux-saga / redux-saga-beginner-tutorial

Redux/Redux-saga beginner tutorial
MIT License
587 stars 542 forks source link

Error running incrementAsync test #36

Open libasoles opened 6 years ago

libasoles commented 6 years ago

I'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. (/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' })
}
dgobaud commented 6 years ago

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.

loanburger commented 3 years ago

I am already using yield call(delay, 1000); and also changed the functions to be exported but getting errors:


> redux-saga-beginner-tutorial@0.0.0 test
> babel-node sagas.spec.js | tap-spec

  incrementAsync Saga test

    redux-saga error: uncaught at check
    call: argument fn is undefined
C:\GIT\redux-saga-beginner-tutorial\src\node_modules\redux-saga\lib\internal\utils.js:45
    throw new Error(error);
    ^

Error: call: argument fn is undefined
    at check (C:\GIT\redux-saga-beginner-tutorial\src\node_modules\redux-saga\lib\internal\utils.js:45:11)
    at getFnCallDesc (C:\GIT\redux-saga-beginner-tutorial\src\node_modules\redux-saga\lib\internal\io.js:108:20)
    at call (C:\GIT\redux-saga-beginner-tutorial\src\node_modules\redux-saga\lib\internal\io.js:133:23)
    at Test.<anonymous> (C:/GIT/redux-saga-beginner-tutorial/src/sagas.spec.js:11:5)
    at Test.bound [as _cb] (C:\GIT\redux-saga-beginner-tutorial\src\node_modules\tape\lib\test.js:88:32)
    at Test.run (C:\GIT\redux-saga-beginner-tutorial\src\node_modules\tape\lib\test.js:105:10)
    at Test.bound [as run] (C:\GIT\redux-saga-beginner-tutorial\src\node_modules\tape\lib\test.js:88:32)
    at Immediate.next (C:\GIT\redux-saga-beginner-tutorial\src\node_modules\tape\lib\results.js:82:19)
    at processImmediate (internal/timers.js:461:21)
Shelley2014 commented 3 years ago

I am already using yield call(delay, 1000); and also changed the functions to be exported but getting errors:

> redux-saga-beginner-tutorial@0.0.0 test
> babel-node sagas.spec.js | tap-spec

  incrementAsync Saga test

    redux-saga error: uncaught at check
    call: argument fn is undefined
C:\GIT\redux-saga-beginner-tutorial\src\node_modules\redux-saga\lib\internal\utils.js:45
    throw new Error(error);
    ^

Error: call: argument fn is undefined
    at check (C:\GIT\redux-saga-beginner-tutorial\src\node_modules\redux-saga\lib\internal\utils.js:45:11)
    at getFnCallDesc (C:\GIT\redux-saga-beginner-tutorial\src\node_modules\redux-saga\lib\internal\io.js:108:20)
    at call (C:\GIT\redux-saga-beginner-tutorial\src\node_modules\redux-saga\lib\internal\io.js:133:23)
    at Test.<anonymous> (C:/GIT/redux-saga-beginner-tutorial/src/sagas.spec.js:11:5)
    at Test.bound [as _cb] (C:\GIT\redux-saga-beginner-tutorial\src\node_modules\tape\lib\test.js:88:32)
    at Test.run (C:\GIT\redux-saga-beginner-tutorial\src\node_modules\tape\lib\test.js:105:10)
    at Test.bound [as run] (C:\GIT\redux-saga-beginner-tutorial\src\node_modules\tape\lib\test.js:88:32)
    at Immediate.next (C:\GIT\redux-saga-beginner-tutorial\src\node_modules\tape\lib\results.js:82:19)
    at processImmediate (internal/timers.js:461:21)

Please check if you export delay also.

jgverges commented 2 years ago

I'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. (/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' })
}

It doenst work for me either

dsurrao commented 2 years ago

delay() should be defined in sagas.js and exported:

export const delay = (ms) => new Promise(res => setTimeout(res, ms))

also, incrementAsync() should yield a call to delay(), this is described in the tutorial:

export function* incrementAsync() {
    yield call(delay, 1000)
    yield put({ type: 'INCREMENT' })
}

See related issue here.