I'm running a test on a function that calls for environment variables, I'm getting undefined. Solutions I tried and didn't work:
1/ add require('dotenv').config({path:'../.env'})
in my test file
2/ pass globals in package.json
"jest": {
"globals": {
"USER_ENDPOINT":"xxx",
"USER_KEY":"xxx"
}
}
3/ pass my variables in test command in package.json
"test": "USER_ENDPOINT:xxx USER_KEY:xxx jest --watchAll --detectOpenHandles"
4/ added an Object.assign in a beforeEach() in my test file
beforeEach(() => {
process.env = Object.assign(process.env, {USER_ENDPOINT:"xxx", USER_KEY:"xxx" });
});
and got the error "Jest encountered an unexpected token"
5/ I created a jest.config.js file on the root
require('dotenv').config({path:'./.env'});
module.exports = {
globals: {
USER_ENDPOINT:"xxx",
USER_KEY:"xxx"
}
};
Most of these solution were suggested here: https://github.com/vuejs/vue-test-utils/issues/193 but none of it worked