Mock Linking - openURL & canOpenURL
Summary: This PR brings 2 basic mocks for `Linking`'s `openURL` & `canOpenURL` methods. Below you can find 2 examples on how to it works. ```javascript it('presses the open website button', () => { const wrapper = shallow(<Info />); expect(wrapper).toBeDefined(); wrapper.find('TouchableOpacity').simulate('press'); expect(Linking.openURL).toHaveBeenCalledTimes(1); expect(Linking.openURL).toHaveBeenCalledWith('https://www.hello.world/'); }); it('presses the call button', () => { const wrapper = shallow(<MoreInfo />); expect(wrapper).toBeDefined(); wrapper.find('TouchableOpacity').simulate('press'); expect(Linking.canOpenURL).toHaveBeenCalledTimes(1); expect(Linking.canOpenURL).toHaveBeenCalledWith('tel:01273123123'); }); ```` Closes https://github.com/facebook/react-native/pull/12839 Differential Revision: D4908903 Pulled By: javache fbshipit-source-id: 0b62e9c2a7f920dc8bf0a49c1973f65c473eb653
This commit is contained in:
parent
de3478c1b1
commit
5121434262
|
@ -131,6 +131,12 @@ const mockNativeModules = {
|
||||||
addListener: jest.fn(),
|
addListener: jest.fn(),
|
||||||
removeListeners: jest.fn(),
|
removeListeners: jest.fn(),
|
||||||
},
|
},
|
||||||
|
Linking: {
|
||||||
|
openURL: jest.fn(),
|
||||||
|
canOpenURL: jest.fn(
|
||||||
|
() => new Promise((resolve) => resolve(true))
|
||||||
|
),
|
||||||
|
},
|
||||||
LocationObserver: {
|
LocationObserver: {
|
||||||
getCurrentPosition: jest.fn(),
|
getCurrentPosition: jest.fn(),
|
||||||
startObserving: jest.fn(),
|
startObserving: jest.fn(),
|
||||||
|
|
Loading…
Reference in New Issue