-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
publicRuntimeConfig undefined in test environment with Jest. #6187
Comments
Duplicate of #4024 Specifically: #4024 (comment) |
Hi all, I think I have a different solution/explanation. I too was hit by tests not passing anymore when upgrading from Next.js 7 to 8. Previously I had a Jest mock in The same is true for It also applies if you used to do Maybe the docs should be updated to reflect the new structure and have |
@damusnet I occurred into the same problem, thank you so much for spotting this! |
This is something we can solve on the Next.js side of things I think 🤔 |
After discussion it was decided instead of rewriting `next/config` and `next/head` imports to `next-server/config` and `next-server/head` we should just allow importing them as `next/config` and `next/head` Fixes: #6187
Bug report
When unit testing a utility function that needs access to the publicRuntimeConfig with jest, it throws error
Cannot read property 'publicRuntimeConfig' of undefined
Describe the bug
For example if i am testing a file that has Contentful stuff in it, and the access token those kind of stuff comes from publicRuntimeConfig, then the test won't past and shows above error.
To Reproduce
// next.config.js
// util.js
util.test.js
System information
The text was updated successfully, but these errors were encountered: