How do I mock the whole @react-native-firebase/messaging
properly in jest
#4298
Unanswered
roni-castro
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Inspiration perhaps is how the module mocks itself for testing? https://github.com/invertase/react-native-firebase/blob/master/jest.setup.ts I do something like /* eslint-disable no-undef */
jest.mock('@react-native-firebase/app', () => ({
messaging: jest.fn(() => ({
hasPermission: jest.fn(() => Promise.resolve(true)),
subscribeToTopic: jest.fn(),
unsubscribeFromTopic: jest.fn(),
requestPermission: jest.fn(() => Promise.resolve(true)),
getToken: jest.fn(() => Promise.resolve('myMockToken')),
})),
notifications: jest.fn(() => ({
onNotification: jest.fn(),
onNotificationDisplayed: jest.fn(),
})),
analytics: jest.fn(() => ({
logEvent: jest.fn(),
setUserProperties: jest.fn(),
setUserId: jest.fn(),
setCurrentScreen: jest.fn(),
})),
}));
// web mock
jest.mock('firebase/app', () => ({
analytics: jest.fn(() => ({
logEvent: jest.fn(),
})),
}));
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am currently mocking this module using this code below, but it does not mock the
FirebaseMessagingTypes
and neither themessaging
(messaging.AuthorizationStatus.PROVISIONAL), how do I mock it? Is there any example on how to mock this lib?Beta Was this translation helpful? Give feedback.
All reactions