I have a config file that changes a variable based on the process.env.NODE_ENV
here is the function:
const { hostname } = window.location
let USE_DEV_TOOLS = false
if (
hostname === 'qa.example.com' ||
hostname === 'dev.example.com' ||
NODE_ENV !== 'production'
) {
USE_DEV_TOOLS = true
}
In my test I want to test that if NODE_ENV
is production, USE_DEV_TOOLS
returns false
however, if I try to change the NODE_ENV
it updates after getting the variable.
import config from 'consts/config'
describe('Environment variables', () => {
const ORIGINAL_ENV = process.env
beforeEach(() => {
jest.resetModules()
process.env = { ...ORIGINAL_ENV }
})
afterAll(() => {
process.env = ORIGINAL_ENV
})
it('production does not use dev tools', () => {
process.env = { NODE_ENV: 'production' }
// console logs properly, but is changing after I get config
console.log(process.env.NODE_ENV)
expect(config.USE_DEV_TOOLS).toBe(false)
})
})