From 5121434262a14b64fad1d61db90b3ec41177e7d6 Mon Sep 17 00:00:00 2001 From: Emmanouil Konstantinidis Date: Wed, 19 Apr 2017 04:10:37 -0700 Subject: [PATCH] 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(); 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(); 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 --- jest/setup.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/jest/setup.js b/jest/setup.js index 579cf0d7a..e2cae1f05 100644 --- a/jest/setup.js +++ b/jest/setup.js @@ -131,6 +131,12 @@ const mockNativeModules = { addListener: jest.fn(), removeListeners: jest.fn(), }, + Linking: { + openURL: jest.fn(), + canOpenURL: jest.fn( + () => new Promise((resolve) => resolve(true)) + ), + }, LocationObserver: { getCurrentPosition: jest.fn(), startObserving: jest.fn(),