-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
TypeError: Cannot read properties of null (reading 'useContext') #124
Comments
As your stacktrace sugggests this error is happening in |
Vitest unfortunately has problems aliasing, this is something we've seen a few times. For reference, vitest-dev/vitest#5004, vitest-dev/vitest#4365 (comment), potentially vitest-dev/vitest#1910 I think this is something Vitest needs to address, not us here. |
Thank you for you fast answer ! Ok, so I added ![]() |
That error says you're loading multiple copies of Preact at once; hooks, in both Preact and React, require that the library is loaded as singleton (only once). Probably the dual-package hazard: vitest-dev/vitest#4365. Again, something that unfortunately needs to be addressed in Vitest (as far as I am aware). |
Vitest team found a workaround😉 |
Describe the bug
Hello,
I'm not able to run Preact components using SWR, in a test environnement.
In dev/prod environnement Preact handles perfectly SWR, but not in test environnement.
When I launch the test, it returns the error :
TypeError: Cannot read properties of null (reading 'useContext')
To Reproduce
Barebone example : https://github.com/dolie/preact-swr-vitest-bug
Steps to reproduce the behavior:
git clone git@github.com:dolie/preact-swr-vitest-bug.git
pnpm i
pnpm vitest
Expected behavior
Preact handles SWR in a test environnement, as it is running in dev/prod environnement.
Additional Context
SWR
Vitest
MSW
Testing-library
The text was updated successfully, but these errors were encountered: