I am using jest react testing library to unit test my application. I am unable to unit test my constant file containing ternary operator for a constant variable.
Code to be tested:
export const ApplicationConstant = {
type: process.env.REACT_APP_NODE_ENV === 'production' ? 'production' : 'development',
}
Unit test code:
import {ApplicationConstant} from './application.constant.js';
test('Check application type',()=>({
expect(ApplicationConstant.type).toBe('production'); //Fails
});
How to get 100% coverage for ternary operator for constant file containing constants?
import {ApplicationConstant} from './application.constant.js';
test('Check application type',()=>({
Object.defineProperty(ApplicationConstant, 'type', {
value: 'production',
})
expect(ApplicationConstant.type).toBe('production');
});