global
variable in JS is not able to access in jest test files, also not able to change the values which are already defined in global.
the work around I have did is as follow:
require('./../../../../bin/global');
describe('gloablAccessMethod', () => {
beforeEach(() => {
// jest.spyOn(regionConfig,'global.regionConfig').mockImplementation(() => ({
// 'ENABLE_CONFIG' : false
// }));
global.regionConfig.ENABLE_CONFIG = false;
});
const PHONE_PREFIX_SG = 65;
it('should access mock global variables', () =>{
//some sample tests
});
});
question from:
https://stackoverflow.com/questions/66047781/global-is-not-defined-in-jest-test-file 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…