Clarification for Testing Environment Variables #38359
Merged
+3
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Documentation / Examples
pnpm lint
The Issue
When it came to testing environment variables with jest in the current release of NextJS, I ran into an issue where my variables were seemingly undefined for no reason. With some research and the help from a friend in discussion post #38353 it was determined further configuration steps were needed in relation to the environment variables for jest. At the time being, no direct link is made between Setting up Jest and Test Environment Variables.
The Change
This fix provides further clarification on the issue by creating a new link within the note on the Setting up Jest page. Moreover, further explanations were added to ensure developers understand the
test
environment is completely separate from bothdevelopment
andproduction
meaning files like.env.development
andenv.prodution
won't be recognized when testing.Supporting Documentation
This is an issue time and time again for developers. Not only have I experienced this, but others have asked on both GitHub Discussions and StackOverflow. Moreover, many of the solutions from 2020 no longer work properly.
I hope this is sufficient enough for a contribution to the documentation. Minor improvements like these create the ideal developer experience Next.js is known for. :)