From d333c60acd4dd3d9f4e58b340785f25a944d476e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Larra=C3=B1aga?= Date: Fri, 25 May 2018 16:42:08 -0700 Subject: [PATCH] Add mock for navigator global --- README.md | 2 +- src/mocks.js | 20 ++++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 187a9fb..08fd516 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ You can also check the [Example App](https://github.com/Xabadu/react-native-jest Mocks currently included: -* Geolocation +* navigator global * Linking * ScrollView * YellowBox diff --git a/src/mocks.js b/src/mocks.js index 280c75d..817f6bb 100644 --- a/src/mocks.js +++ b/src/mocks.js @@ -20,18 +20,14 @@ module.exports = { } }); - /* Geolocation, required by the navigation global */ - jest.mock('Geolocation', () => ({ - clearWatch: jest.fn(), - getCurrentPosition: jest.genMockFn().mockReturnValue({ - city: 'San Francisco', - state: 'CA', - lat: 37.785834, - lng: -122.406417 - }), - stopObserving: jest.fn(), - watchPosition: jest.fn() - })); + global.navigator = { + geolocation: { + clearWatch: jest.fn(), + getCurrentPosition: jest.fn(), + stopObserving: jest.fn(), + watchPosition: jest.fn() + } + }; jest.mock('ScrollView', () => jest.genMockFromModule('ScrollView')); jest.mock('YellowBox', () => jest.genMockFromModule('YellowBox'));