Jest – Mock a constant property from a module for a specific test
File that exports a constant value that I want to mock: // utils/deviceTypeUtils file import DeviceInfo from ‘react-native-device-info’; export const isTablet = DeviceInfo.isTablet(); In my test file, I use this code to mock the constant isTablet: // file: deviceTypeUtils.spec const DeviceTypeUtilsMock = jest.requireMock(‘../utils/deviceTypeUtils’); jest.mock(‘../utils/deviceTypeUtils’, () => ({ isTablet: false, })); describe(‘mock const example’, () => … Read more