'React environmental variable flags in test file but does not show in console as error

I have an environmental variable that comes from a .env file that gets compiled from a env.config.js. I have used this approach: https://www.freecodecamp.org/news/how-to-implement-runtime-environment-variables-with-create-react-app-docker-and-nginx-7f9d42a91d70/

I am using as below:

const url = `${window._env_.REACT_APP_URL}`

All seems to be working, however in my test console Jest is flagging by saying:

  TypeError: Cannot read property 'REACT_APP_URL' of undefined

Any idea's why?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source