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:
Emmanouil Konstantinidis 2017-04-19 04:10:37 -07:00 committed by Facebook Github Bot
parent de3478c1b1
commit 5121434262
1 changed files with 6 additions and 0 deletions

View File

@ -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(),