-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mock Linking - openURL & canOpenURL #12839
Conversation
jest/setup.js
Outdated
Linking: { | ||
openURL: jest.fn(), | ||
canOpenURL: jest.fn( | ||
(url) => new Promise((resolve) => resolve(url)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return a boolean:
https://github.com/facebook/react-native/blob/master/Libraries/Linking/Linking.js#L164
Good idea, thanks for doing it! Just one nit. |
@mkonicek I forgot about this PR - Is there anything else I need to change? |
@javache has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
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 facebook#12839 Differential Revision: D4908903 Pulled By: javache fbshipit-source-id: 0b62e9c2a7f920dc8bf0a49c1973f65c473eb653
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 facebook#12839 Differential Revision: D4908903 Pulled By: javache fbshipit-source-id: 0b62e9c2a7f920dc8bf0a49c1973f65c473eb653
This PR brings 2 basic mocks for
Linking
'sopenURL
&canOpenURL
methods. Below you can find 2 examples on how to it works.