Issues with Jest and .env.test
#464
Unanswered
cal-overflow
asked this question in
Q&A
Replies: 2 comments 2 replies
-
@goatandsheep do you have any idea on how to resolve this? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Still haven't found a solution for this. I just created a wrapper module that I can easily mock. It would be nice if there was clarity around this, though. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have read both the docs and existing posts several times now. I currently have an issue when running my jest tests.
Here's a minimal recreation of my setup:
.env
babel.config.js
When I run my application, everything works as expected. The values from
.env
are loaded in correctly. Here's an example of how I use these variables in my project.src/WelcomeScreen.js
Like I mentioned above, this works when I build the app using metro. I would see
variable value: real_value
as the log output.The issue
The problem comes when I run jest. Following the docs, I have created a special
.env.test
file with a different set of values..env.test
When I run my test files, I see that these
.env.test
variable values are used. For example:src/WelcomeScreen.test.js
Shows
variable value: test_value
.However, the reference to
MY_VAR
insrc/WelcomeScreen.js
will throw the following error.At this point I'm unsure if there is a configuration setting I'm missing or there is something going on with Jest that is interfering with how the module is being loaded into the non-test files.
Any suggestions are welcome!
Related:
Beta Was this translation helpful? Give feedback.
All reactions