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:
ZauberNerd 2017-05-11 03:36:55 -07:00 коммит произвёл Facebook Github Bot
Родитель 3e46c051d3
Коммит 31a0b8788f
1 изменённых файлов: 18 добавлений и 0 удалений

Просмотреть файл

@ -156,6 +156,24 @@ const mockNativeModules = {
addListener: jest.fn(), addListener: jest.fn(),
removeListeners: 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: { SourceCode: {
scriptURL: null, scriptURL: null,
}, },