Попытка проверить библиотеку, которая использует navigator.geolocation
в react-native
.
Ошибка:
IL __tests__/accessMgr.test.js
● Test suite failed to run
Invariant Violation: Native module cannot be null.
at invariant (node_modules/fbjs/lib/invariant.js:44:15)
at new NativeEventEmitter (node_modules/react-native/Libraries/EventEmitter/NativeEventEmitter.js:32:1)
at Object.<anonymous> (node_modules/react-native/Libraries/Geolocation/Geolocation.js:21:26)
at node_modules/react-native/Libraries/Core/InitializeCore.js:196:58
at Object.getValue [as geolocation] (node_modules/react-native/Libraries/Utilities/defineLazyObjectProperty.js:44:10)
at Object.<anonymous> (src/tools/accessmgr/geo.js:5:41)
Строка, дающая ошибку:
const { geolocation: { getCurrentPosition } } = navigator;
Тест:
import AccessMgr from '../src/tools/accessmgr/accessmgr';
const P = Promise;
const mockFn = jest.fn().mockImplementation;
const coords = {
coords: {
latitude: 51.1,
longitude: 45.3,
},
};
const mockGeolocation = {
getCurrentPosition: mockFn(yeah => P.resolve(yeah(coords))),
};
navigator.geolocation = mockGeolocation;
test('isDeviceReady returns true if all services has access granted', () => {
const accessMgr = new AccessMgr({
photobook: true,
geo: true,
push: true,
});
expect(accessMgr.isDeviceReady()).toBeTruthy();
});