mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 01:40:08 +00:00
Add jest mock for 'PushNotificationManager'
Summary: `PushNotificationIOS` is a library that makes use of the `PushNotificationManager` native module. This commit adds a jest mock for its native module so that code that uses `PushNotificationIOS` can be tested using jest. In order to enable behaviour in unit tests it is possible to replace or overwrite the mock implementation, see the [jest guide on mocks](https://facebook.github.io/jest/docs/mock-functions.html). By doing something similar to: ```javascript import { NativeModules } from 'react-native'; const { PushNotificationManager } = NativeModules; // mock 'checkPermissions' to return a different value than the default: PushNotificationManager.checkPermissions.mockImplementationOnce((callback) => { // execute callback in next tick to enable async behaviour process.nextTick(() => callback({ alert: false, badge: false, sound: false })); }); // execute unit tests for code that makes use of 'PushNotificationIOS' ``` Closes https://github.com/facebook/react-native/pull/13410 Differential Revision: D5043904 Pulled By: cpojer fbshipit-source-id: 11e73cd215ba6854d06f4ac7a5aea0ab4be26584
This commit is contained in:
parent
3e46c051d3
commit
31a0b8788f
@ -156,6 +156,24 @@ const mockNativeModules = {
|
||||
addListener: jest.fn(),
|
||||
removeListeners: jest.fn(),
|
||||
},
|
||||
PushNotificationManager: {
|
||||
presentLocalNotification: jest.fn(),
|
||||
scheduleLocalNotification: jest.fn(),
|
||||
cancelAllLocalNotifications: jest.fn(),
|
||||
removeAllDeliveredNotifications: jest.fn(),
|
||||
getDeliveredNotifications: jest.fn(callback => process.nextTick(() => [])),
|
||||
removeDeliveredNotifications: jest.fn(),
|
||||
setApplicationIconBadgeNumber: jest.fn(),
|
||||
getApplicationIconBadgeNumber: jest.fn(callback => process.nextTick(() => callback(0))),
|
||||
cancelLocalNotifications: jest.fn(),
|
||||
getScheduledLocalNotifications: jest.fn(callback => process.nextTick(() => callback())),
|
||||
requestPermissions: jest.fn(() => Promise.resolve({alert: true, badge: true, sound: true})),
|
||||
abandonPermissions: jest.fn(),
|
||||
checkPermissions: jest.fn(callback => process.nextTick(() => callback({alert: true, badge: true, sound: true}))),
|
||||
getInitialNotification: jest.fn(() => Promise.resolve(null)),
|
||||
addListener: jest.fn(),
|
||||
removeListeners: jest.fn(),
|
||||
},
|
||||
SourceCode: {
|
||||
scriptURL: null,
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user