I was trying to test a func using jest where I need to mock webpack defined global to test all the cases. I was unale to do so.
// webpack.config.js
...
new webpack.DefinePlugin({
__ENV__: `'${process.env.NODE_ENV}'`
}),
...
// commonUtil.js
const log = __ENV__ !== envs.PROD ? console.log.bind(console) : () => {};
// commonUtil.jest.js
describe('commonUtils', () => {
const test = 'test';
it('should log to the console in non-production environment', () => {
__ENV__ = envs.PROD;
log(test);
});
it('should log to the console in non-production environment', () => {
__ENV__ = envs.DEV;
log(test);
});
});
New contributor
Arpit Malik is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.