Add Geolocation API Jest mock#13442
Add Geolocation API Jest mock#13442willdurand wants to merge 1 commit intofacebook:masterfrom willdurand:patch-2
Conversation
jest/setup.js
Outdated
| Geolocation: { | ||
| getCurrentPosition: jest.fn(), | ||
| watchPosition: jest.fn(), | ||
| clearWatch: jest.fn(), |
There was a problem hiding this comment.
Instead of mocking watchPosition and clearWatch, can you just mock startObserving()? We should only need to mock the native APIs here.
There was a problem hiding this comment.
One question though, I looked at this definition to decide on the methods to mock, but you say I should only mock the native APIs. Should I completely omit the Geolocation JS class, and only mock the native methods? (then, I would have to mock getCurrentPosition() and stopObserving() on the LocationObserver too.
There was a problem hiding this comment.
Yeah, you should only add a mock for the NativeModule, so you probably want to add startObserving there, and remove the LocationObserver mock
There was a problem hiding this comment.
@javache Isn't LocationObserver the native module?
There was a problem hiding this comment.
Ah yes, my bad. I guess the mocks you have on Geolocation should move to LocationObserver then
There was a problem hiding this comment.
@javache alright, updated to only mock the LocationObserver :)
The [Geolocation API](https://facebook.github.io/react-native/docs/geolocation.html) is currently not mocked in Jest, which often leads to an `Invariant Violation: Native module cannot be null` error.
|
@javache has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Summary: Hello! The [Geolocation API](https://facebook.github.io/react-native/docs/geolocation.html) is currently not mocked in Jest, which often leads to an `Invariant Violation: Native module cannot be null` error. This patch adds a basic Jest configuration similar to the existing ones for the other modules. None unfortunately, but this patch makes my test suite all green 😉 Thanks, William Closes facebook#13442 Differential Revision: D4883830 Pulled By: javache fbshipit-source-id: c2a976834cca7537bd832a698e8cd25cf877705b
Summary: Hello! The [Geolocation API](https://facebook.github.io/react-native/docs/geolocation.html) is currently not mocked in Jest, which often leads to an `Invariant Violation: Native module cannot be null` error. This patch adds a basic Jest configuration similar to the existing ones for the other modules. None unfortunately, but this patch makes my test suite all green 😉 Thanks, William Closes facebook#13442 Differential Revision: D4883830 Pulled By: javache fbshipit-source-id: c2a976834cca7537bd832a698e8cd25cf877705b
Hello!
Motivation (required)
The Geolocation API is currently not mocked in Jest, which often leads to an
Invariant Violation: Native module cannot be nullerror. This patch adds a basic Jest configuration similar to the existing ones for the other modules.Test Plan (required)
None unfortunately, but this patch makes my test suite all green 😉
Thanks,
William