Skip to content

Instantly share code, notes, and snippets.

@maml
Created November 1, 2018 21:26
Show Gist options
  • Save maml/379ee6adfda02a28afb4c6d957f7cc86 to your computer and use it in GitHub Desktop.
Save maml/379ee6adfda02a28afb4c6d957f7cc86 to your computer and use it in GitHub Desktop.
react-native-firebase jest mock
jest.mock('react-native-firebase', () => {
return {
admob: jest.fn(() => {
return {
onNotification: jest.fn(),
onNotificationDisplayed: jest.fn()
}
}),
analytics: jest.fn(() => {
return {
onNotification: jest.fn(),
onNotificationDisplayed: jest.fn()
}
}),
auth: jest.fn(() => {
return {
hasPermission: jest.fn(() => Promise.resolve(true)),
subscribeToTopic: jest.fn(),
unsubscribeFromTopic: jest.fn(),
requestPermission: jest.fn(() => Promise.resolve(true)),
getToken: jest.fn(() => Promise.resolve('RN-Firebase-Token'))
}
}),
crashlytics: jest.fn(() => {
return {
onNotification: jest.fn(),
onNotificationDisplayed: jest.fn()
}
}),
firestore: jest.fn(() => {
return {
onNotification: jest.fn(),
onNotificationDisplayed: jest.fn()
}
}),
perf: jest.fn(() => {
return {
onNotification: jest.fn(),
onNotificationDisplayed: jest.fn()
}
}),
links: jest.fn(() => {
return {
onNotification: jest.fn(),
onNotificationDisplayed: jest.fn()
}
}),
database: jest.fn(() => {
return {
onNotification: jest.fn(),
onNotificationDisplayed: jest.fn()
}
}),
config: jest.fn(() => {
return {
onNotification: jest.fn(),
onNotificationDisplayed: jest.fn()
}
}),
storage: jest.fn(() => {
return {
onNotification: jest.fn(),
onNotificationDisplayed: jest.fn()
}
}),
iid: jest.fn(() => {
return {
onNotification: jest.fn(),
onNotificationDisplayed: jest.fn()
}
}),
messaging: jest.fn(() => {
return {
hasPermission: jest.fn(() => Promise.resolve(true)),
subscribeToTopic: jest.fn(),
unsubscribeFromTopic: jest.fn(),
requestPermission: jest.fn(() => Promise.resolve(true)),
getToken: jest.fn(() => Promise.resolve('RN-Firebase-Token'))
}
}),
notifications: jest.fn(() => {
return {
onNotification: jest.fn(),
onNotificationDisplayed: jest.fn()
}
})
}
})
...
"jest": {
"preset": "react-native",
"setupTestFrameworkScriptFile": "./jest.mock.rn-firebase",
"automock": false
},
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment