Incompatible with Jest 26+
See original GitHub issueWhen 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:
- Created 3 years ago
- Reactions:3
- Comments:7 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Working on the fix. It’ll be released by the end of Wednesday (GMT).
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.