I have configured an app for code-push, it works well except for jest tests. It fails in rendering app for this error:
TypeError: Cannot read property 'CheckFrequency' of undefined
at Object.<anonymous> (app/index.js:7:66)
at Object.<anonymous> (index.ios.js:5:12)
at Object.<anonymous> (__tests__/index.ios.js:4:12)
in this line:
const codePushOptions = { checkFrequency: codePush.CheckFrequency.MANUAL };
The test code is:
import App from '../index.ios';
it('renders correctly', () => {
const tree = renderer.create(
<App />,
);
});
I came across this problem while integrating codePush
into the React Native app I am currently working on. What worked for me was:
__mocks__/react-native-code-push.js
.Adding the following code to it:
const codePush = {
InstallMode: {ON_NEXT_RESTART: 'ON_APP_RESTART'},
CheckFrequency: {ON_APP_RESUME: 'ON_APP_RESUME'}
};
const cb = _ => app => app;
Object.assign(cb, codePush);
export default cb;
On my index.js
file, I have:
import codePush from 'react-native-code-push';
import MyApp from './src/'
const codePushOptions = {
installMode: codePush.InstallMode.ON_NEXT_RESTART,
checkFrequency: codePush.CheckFrequency.ON_APP_RESUME
};
export default codePush(codePushOptions)(MyApp);
Similar to what Tom Hall describes, this mock does work for me:
jest.mock('react-native-code-push', () => {
const cp = (_: any) => (app: any) => app;
Object.assign(cp, {
InstallMode: {},
CheckFrequency: {},
SyncStatus: {},
UpdateState: {},
DeploymentStatus: {},
DEFAULT_UPDATE_DIALOG: {},
checkForUpdate: jest.fn(),
codePushify: jest.fn(),
getConfiguration: jest.fn(),
getCurrentPackage: jest.fn(),
getUpdateMetadata: jest.fn(),
log: jest.fn(),
notifyAppReady: jest.fn(),
notifyApplicationReady: jest.fn(),
sync: jest.fn(),
});
return cp;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With