-
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
Add Geolocation API Jest mock #13442
Conversation
jest/setup.js
Outdated
Geolocation: { | ||
getCurrentPosition: jest.fn(), | ||
watchPosition: jest.fn(), | ||
clearWatch: jest.fn(), |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sure!
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@javache Isn't LocationObserver
the native module?
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.
Ah yes, my bad. I guess the mocks you have on Geolocation should move to LocationObserver then
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.
@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 null
error. 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