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.

Incompatible with Jest 26+

See original GitHub issue

When running with Jest 26.6.0 (with Create-React-App v4), all of my tests now fail with the error ‘Hooks cannot be defined inside tests. Hook of type “beforeEach” is nested within “Test Name”’. This was mentioned as one of the issues in this previous issue , of which the fix was to upgrade to v1.4.2 of jest-react-hooks-shallow. This, however, has not fixed it. Is there some other configuration that is required to make it work with Jest 26.6.0?

Stacktrace:

Error: Hooks cannot be defined inside tests. Hook of type "beforeEach" is nested within "toggles tigonMode and saves it in sessionStore".
    at eventHandler (/Users/robwaddell/src/git/string-dashboard/client/node_modules/jest-circus/build/eventHandler.js:105:11)
    at dispatchSync (/Users/robwaddell/src/git/string-dashboard/client/node_modules/jest-circus/build/state.js:65:5)
    at _addHook (/Users/robwaddell/src/git/string-dashboard/client/node_modules/jest-circus/build/index.js:125:27)
    at beforeEach (/Users/robwaddell/src/git/string-dashboard/client/node_modules/jest-circus/build/index.js:135:3)
    at Object.mockUseEffect [as default] (/Users/robwaddell/src/git/string-dashboard/client/node_modules/jest-react-hooks-shallow/src/mock-use-effect/mock-use-effect.ts:14:3)
    at withHooks (/Users/robwaddell/src/git/string-dashboard/client/node_modules/jest-react-hooks-shallow/src/enable-hooks.ts:47:49)
    at Object.<anonymous> (/Users/robwaddell/src/git/string-dashboard/client/src/app/App.test.jsx:54:7)
    at Promise.then.completed (/Users/robwaddell/src/git/string-dashboard/client/node_modules/jest-circus/build/utils.js:276:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/Users/robwaddell/src/git/string-dashboard/client/node_modules/jest-circus/build/utils.js:216:10)
    at _callCircusTest (/Users/robwaddell/src/git/string-dashboard/client/node_modules/jest-circus/build/run.js:212:40)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at _runTest (/Users/robwaddell/src/git/string-dashboard/client/node_modules/jest-circus/build/run.js:149:3)
    at _runTestsForDescribeBlock (/Users/robwaddell/src/git/string-dashboard/client/node_modules/jest-circus/build/run.js:63:9)
    at _runTestsForDescribeBlock (/Users/robwaddell/src/git/string-dashboard/client/node_modules/jest-circus/build/run.js:57:9)
    at _runTestsForDescribeBlock (/Users/robwaddell/src/git/string-dashboard/client/node_modules/jest-circus/build/run.js:57:9)
    at run (/Users/robwaddell/src/git/string-dashboard/client/node_modules/jest-circus/build/run.js:25:3)
    at runAndTransformResultsToJestFormat (/Users/robwaddell/src/git/string-dashboard/client/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:176:21)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
mikeborozdincommented, Feb 22, 2021

Working on the fix. It’ll be released by the end of Wednesday (GMT).

2reactions
EricKulchyckicommented, Feb 18, 2021

Hello @mikeborozdin, I was wondering if there’s been any progress on this issue as it is blocking me from upgrading react-scripts to the newest version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest 27: New Defaults for Jest, 2021 edition
We introduced an opt-in "modern" implementation of Fake Timers in Jest 26 accessed transparently through the same API, but with much more ...
Read more >
Issue with babel-jest dependency when running npm start in a ...
This problem can occur if there is node_modules in a parent directory of the folder where you run the application. I solved the...
Read more >
ts-jest | Yarn - Package Manager
readme. ts-jest. A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript.
Read more >
ts-jest - npm
A Jest transformer with source map support that lets you use Jest to test projects written in TypeScript. Latest version: 29.0.3, ...
Read more >
Version checking | ts-jest - GitHub Pages
By default, ts-jest supports a range of versions for jest/typescript. One uses incompatible versions will receive a warning.
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