I'm writing tests for my Express project, but when I run the test script my environment variables are not loaded.
In other threads people suggested using --setupFiles dotenv/config
, which I did, but unfortunately it didn't work. I tried both adding it to my test script and to a jest.config.js
file, but none worked. Does someone have any hint on how to fix this?
Context
This is how I setup jest on package.json
:
"scripts": {
"test": "jest --watchAll --setupFiles dotenv/config"
},
"jest": {
"testEnvironment": "node"
},
At the top of my app.js
file, I load my environment variables with
require('dotenv').config();
And this is my folder structure: