From 1d37c81163208bee8d8f697c0a77ea369fec68f4 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Tue, 13 Aug 2019 12:51:51 -0400 Subject: [PATCH] Fix tests (#3114) --- app/init/global_event_handler.test.js | 18 ++++++++++++++---- test/setup.js | 6 ++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/init/global_event_handler.test.js b/app/init/global_event_handler.test.js index a3abef9f5..ec0fe40f0 100644 --- a/app/init/global_event_handler.test.js +++ b/app/init/global_event_handler.test.js @@ -4,25 +4,35 @@ import configureMockStore from 'redux-mock-store'; import thunk from 'redux-thunk'; +import intitialState from 'app/initial_state'; import PushNotification from 'app/push_notifications'; import GlobalEventHandler from './global_event_handler'; jest.mock('app/init/credentials', () => ({ + getCurrentServerUrl: jest.fn().mockResolvedValue(''), getAppCredentials: jest.fn(), removeAppCredentials: jest.fn(), })); +jest.mock('react-native-notifications', () => ({ + addEventListener: jest.fn(), + cancelAllLocalNotifications: jest.fn(), + setBadgesCount: jest.fn(), + NotificationAction: jest.fn(), + NotificationCategory: jest.fn(), +})); + const mockStore = configureMockStore([thunk]); -const store = mockStore({}); +const store = mockStore(intitialState); GlobalEventHandler.store = store; // TODO: Add Android test as part of https://mattermost.atlassian.net/browse/MM-17110 describe('GlobalEventHandler', () => { - it('should clear notifications on logout', () => { + it('should clear notifications on logout', async () => { const clearNotifications = jest.spyOn(PushNotification, 'clearNotifications'); - GlobalEventHandler.onLogout(); + await GlobalEventHandler.onLogout(); expect(clearNotifications).toHaveBeenCalled(); }); -}); \ No newline at end of file +}); diff --git a/test/setup.js b/test/setup.js index 0ce565914..fd80f20bd 100644 --- a/test/setup.js +++ b/test/setup.js @@ -8,6 +8,7 @@ configure({adapter: new Adapter()}); const mockImpl = new MockAsyncStorage(); jest.mock('@react-native-community/async-storage', () => mockImpl); +global.window = {}; /* eslint-disable no-console */ @@ -38,6 +39,10 @@ jest.mock('NativeModules', () => { SECURITY_LEVEL_SECURE_SOFTWARE: 'SOFTWARE', SECURITY_LEVEL_SECURE_HARDWARE: 'HARDWARE', }, + RNCNetInfo: { + addEventListener: jest.fn(), + getCurrentState: jest.fn().mockResolvedValue({isConnected: true}), + }, }; }); jest.mock('NativeEventEmitter'); @@ -48,6 +53,7 @@ jest.mock('react-native-device-info', () => { getBuildNumber: () => '0', getModel: () => 'iPhone X', isTablet: () => false, + getDeviceLocale: () => 'en-US', }; });