Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of a non-generator function as the callback to takeEvery results in: TypeError: Cannot read properties of undefined (reading 'next') #391

Open
JackStandbridgeCS opened this issue Dec 20, 2023 · 0 comments

Comments

@JackStandbridgeCS
Copy link

Summary

When a takeEvery has a non-generator function as the second argument, the saga runs fine in the application, but errors when it is run by redux-saga-test-plan's expectSaga.

Expected behaviour

There is no error in the test when there is no error in the application code.

Actual behaviour

This error is printed in the terminal:

TypeError: Cannot read properties of undefined (reading 'next')
    at getNext (project/node_modules/redux-saga-test-plan/lib/expectSaga/sagaWrapper.js:51:32)
    at Object.INIT (project/node_modules/redux-saga-test-plan/lib/expectSaga/sagaWrapper.js:74:18)
    at Object.next (project/node_modules/fsm-iterator/lib/index.js:91:37)
    at next (project/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:1161:27)
    at proc (project/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:1112:3)
    at project/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:589:17
    at immediately (project/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:60:12)
    at runForkEffect (project/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:588:3)
    at runEffect (project/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:1208:7)
    at digestEffect (project/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:1275:5)
    at next (project/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:1165:9)
    at currCb (project/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:1255:7)
    at takeCb (project/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:507:5)
    at put (project/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:343:9)
    at project/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:380:7
    at exec (project/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:35:5)
    at flush (project/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:91:5)
    at asap (project/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:50:5)
    at Object.chan.put (project/node_modules/@redux-saga/core/dist/redux-saga-core.dev.cjs.js:379:5)
    at notifyListeners (project/node_modules/redux-saga-test-plan/lib/expectSaga/index.js:327:15)
    at project/node_modules/redux-saga-test-plan/lib/expectSaga/index.js:341:34
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Reproduction

import { expectSaga } from "redux-saga-test-plan";
import { takeEvery } from "redux-saga/effects";

const repro = function* () {
  yield takeEvery("action", () => {});
};

describe(repro, () => {
  it("should not error", () => {
    return expectSaga(repro).dispatch({ type: "action" }).silentRun(0);
  });
});

Updating the takeEvery to yield takeEvery("action", function* () {}); causes the error to go away, however, both the generator and non-generator versions work when running in my application.

Dependencies

These are the versions I have in the project:

    "redux-saga": "1.2.3",
    "redux-saga-test-plan": "4.0.6",

And I'm running the tests with node v16.15.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant