question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: batch is not a function in Jest

See original GitHub issue
    TypeError: batch is not a function
      at Object.batch [as notify] (node_modules/react-redux/lib/utils/Subscription.js:29:7)
      at Subscription.notify [as notifyNestedSubs] (node_modules/react-redux/lib/utils/Subscription.js:71:20)
      at notifyNestedSubs (node_modules/react-redux/lib/components/connectAdvanced.js:272:13)
      at checkForUpdates (node_modules/react-redux/lib/components/connectAdvanced.js:296:9)
      at create (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:10867:26)
      at commitHookEffectList (node_modules/react-test-renderer/cjs/react-test-renderer.develo

Versions

    "react": "^16.9.0",
    "react-native": "0.60.5",
    "react-redux": "7.0.0",
    "redux": "^4.0.0",
    "redux-persist": "^5.10.0",

Once I updated to 7.0, this problem appears in all test cases using react-redux. When I go into node_modules/react-redux/lib/utils/Subscription.js and change line

var batch = (0, _batch.getBatch)(); to var batch = (0, _batch.getBatch);

it works fine

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
alnorriscommented, Sep 9, 2019

Was able to temporarily get around the issue with this.

jest.mock('../../node_modules/react-redux/lib/utils/batch.js', () => ({
  setBatch: jest.fn(),
  getBatch: () => fn => fn()
}))
0reactions
shirakabacommented, Dec 14, 2019

In case it helps anyone, here is how I’ve attempted to implement unstable_batchedUpdates for my React custom renderer without creating a dependency upon React DOM or React Native. It’s undocumented, so I have no idea.

My app is now freezing at run-time post state update, rather than crashing at startup, so I think it’s at least a step in the right direction. And the latter part about freezing may not even be related.

EDIT: My methodology seems to be exactly the same as that used by react-three, so I can at least have some confidence in advising it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: this.dynamodb.batchGetItem is not a function with jest
You can use jest.spyOn(object, methodName) to mock AWS.DynamoDB class and its instance. Use mockFn.mockReturnThis() to mock method chain ...
Read more >
jest.Mock.mockImplementation JavaScript and Node.js code ...
Accepts a function that should be used as the implementation of the mock. The mock itself will still record all calls that go...
Read more >
batch | React Redux
If you're using React 18, you do not need to use the batch API. React 18 automatically batches all state updates, no matter...
Read more >
How to mock function of module - Medium
Way3: use jest.mock to mock specific module function ... const module = jest. ... TimeCop is not working when using Shared_examples.
Read more >
Expect a function to throw an exception in Jest - eloquent code
Unit testing functions in JavaScript using Jest sometimes requires checking if an ... We can also assert that an error is not thrown...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found