react-navigation/jest-setup.js

46 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2017-05-15 19:02:46 -07:00
/**
* @flow
* eslint-env jest
2017-05-15 19:02:46 -07:00
*/
import React from 'react';
2017-05-15 19:02:46 -07:00
// See https://github.com/facebook/jest/issues/2208
jest.mock('Linking', () => ({
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
openURL: jest.fn(),
canOpenURL: jest.fn(),
getInitialURL: jest
.fn()
.mockImplementation((value: string) => Promise.resolve(value)),
}));
// See https://github.com/facebook/react-native/issues/11659
jest.mock('ScrollView', () => {
// $FlowExpectedError
const RealComponent = require.requireActual('ScrollView');
class ScrollView extends RealComponent {
scrollTo = () => {};
}
return ScrollView;
});
// Mock setState so it waits using setImmediate before actually being called,
// so we can use jest's mock timers to control it.
// setState in the test renderer is sync instead of async like react and react-native.
// This doesn't work with our NavigationContainer tests which test react-navigation's
// behaviour against the async nature of setState.
const setState = React.Component.prototype.setState;
// $FlowExpectedError
Object.defineProperty(React.Component.prototype, 'setState', {
value: function() {
setImmediate(() => {
setState.apply(this, arguments);
});
},
});
2017-05-15 19:02:46 -07:00
// $FlowExpectedError
Date.now = jest.fn(() => 0);