From 5aac68e785c5d8dc50b82a44303a6d372291c534 Mon Sep 17 00:00:00 2001 From: Sudheer Date: Fri, 14 Sep 2018 20:44:37 +0530 Subject: [PATCH] Change rn-fetch-blob to mock globally in jest (#2124) --- app/actions/views/login.test.js | 7 ------- app/actions/views/select_server.test.js | 7 ------- app/actions/views/thread.test.js | 7 ------- .../user_list_row/user_list_test.test.js | 16 ---------------- app/screens/select_team/select_team.test.js | 16 ---------------- app/screens/user_profile/user_profile.test.js | 15 --------------- app/store/middleware.test.js | 7 ------- test/setup.js | 16 ++++++++++++++++ 8 files changed, 16 insertions(+), 75 deletions(-) diff --git a/app/actions/views/login.test.js b/app/actions/views/login.test.js index ba1ca9c9a..062f3683b 100644 --- a/app/actions/views/login.test.js +++ b/app/actions/views/login.test.js @@ -11,13 +11,6 @@ import { handlePasswordChanged, } from 'app/actions/views/login'; -jest.mock('rn-fetch-blob/fs', () => ({ - dirs: { - DocumentDir: () => jest.fn(), - CacheDir: () => jest.fn(), - }, -})); - jest.mock('app/mattermost', () => ({ app: { setAppCredentials: () => jest.fn(), diff --git a/app/actions/views/select_server.test.js b/app/actions/views/select_server.test.js index d1718b48a..f89135053 100644 --- a/app/actions/views/select_server.test.js +++ b/app/actions/views/select_server.test.js @@ -11,13 +11,6 @@ import {ViewTypes} from 'app/constants'; import {handleServerUrlChanged} from 'app/actions/views/select_server'; -jest.mock('rn-fetch-blob/fs', () => ({ - dirs: { - DocumentDir: () => jest.fn(), - CacheDir: () => jest.fn(), - }, -})); - const mockStore = configureStore([thunk]); describe('Actions.Views.SelectServer', () => { diff --git a/app/actions/views/thread.test.js b/app/actions/views/thread.test.js index be0067c96..ce1acfbfc 100644 --- a/app/actions/views/thread.test.js +++ b/app/actions/views/thread.test.js @@ -11,13 +11,6 @@ import { handleCommentDraftSelectionChanged, } from 'app/actions/views/thread'; -jest.mock('rn-fetch-blob/fs', () => ({ - dirs: { - DocumentDir: () => jest.fn(), - CacheDir: () => jest.fn(), - }, -})); - const mockStore = configureStore([thunk]); describe('Actions.Views.Thread', () => { diff --git a/app/components/custom_list/user_list_row/user_list_test.test.js b/app/components/custom_list/user_list_row/user_list_test.test.js index 1698dd802..a7e743d8a 100644 --- a/app/components/custom_list/user_list_row/user_list_test.test.js +++ b/app/components/custom_list/user_list_row/user_list_test.test.js @@ -17,22 +17,6 @@ jest.mock('app/utils/theme', () => { }; }); -jest.mock('rn-fetch-blob', () => ({ - fs: { - dirs: { - DocumentDir: () => jest.fn(), - CacheDir: () => jest.fn(), - }, - }, -})); - -jest.mock('rn-fetch-blob/fs', () => ({ - dirs: { - DocumentDir: () => jest.fn(), - CacheDir: () => jest.fn(), - }, -})); - describe('UserListRow', () => { const formatMessage = jest.fn(); const baseProps = { diff --git a/app/screens/select_team/select_team.test.js b/app/screens/select_team/select_team.test.js index 892b0afd4..ad2f03028 100644 --- a/app/screens/select_team/select_team.test.js +++ b/app/screens/select_team/select_team.test.js @@ -7,22 +7,6 @@ import {RequestStatus} from 'mattermost-redux/constants'; import SelectTeam from './select_team.js'; -jest.mock('rn-fetch-blob', () => ({ - fs: { - dirs: { - DocumentDir: () => jest.fn(), - CacheDir: () => jest.fn(), - }, - }, -})); - -jest.mock('rn-fetch-blob/fs', () => ({ - dirs: { - DocumentDir: () => jest.fn(), - CacheDir: () => jest.fn(), - }, -})); - jest.mock('app/utils/theme', () => { const original = require.requireActual('app/utils/theme'); return { diff --git a/app/screens/user_profile/user_profile.test.js b/app/screens/user_profile/user_profile.test.js index 3821c5771..14fe37d82 100644 --- a/app/screens/user_profile/user_profile.test.js +++ b/app/screens/user_profile/user_profile.test.js @@ -5,21 +5,6 @@ import {shallow} from 'enzyme'; jest.mock('react-intl'); import UserProfile from './user_profile.js'; -jest.mock('rn-fetch-blob', () => ({ - fs: { - dirs: { - DocumentDir: () => jest.fn(), - CacheDir: () => jest.fn(), - }, - }, -})); - -jest.mock('rn-fetch-blob/fs', () => ({ - dirs: { - DocumentDir: () => jest.fn(), - CacheDir: () => jest.fn(), - }, -})); jest.mock('app/utils/theme', () => { const original = require.requireActual('app/utils/theme'); diff --git a/app/store/middleware.test.js b/app/store/middleware.test.js index 38912c92e..b4d4de8cf 100644 --- a/app/store/middleware.test.js +++ b/app/store/middleware.test.js @@ -8,13 +8,6 @@ import assert from 'assert'; import {ViewTypes} from 'app/constants'; import {messageRetention} from 'app/store/middleware'; -jest.mock('rn-fetch-blob/fs', () => ({ - dirs: { - DocumentDir: () => jest.fn(), - CacheDir: () => jest.fn(), - }, -})); - jest.mock('react-native-device-info', () => { return { getVersion: () => '0.0.0', diff --git a/test/setup.js b/test/setup.js index eef7a3907..1484fe689 100644 --- a/test/setup.js +++ b/test/setup.js @@ -41,3 +41,19 @@ afterEach(() => { throw new Error('Unexpected console logs' + logs + warns + errors); } }); + +jest.mock('rn-fetch-blob', () => ({ + fs: { + dirs: { + DocumentDir: () => jest.fn(), + CacheDir: () => jest.fn(), + }, + }, +})); + +jest.mock('rn-fetch-blob/fs', () => ({ + dirs: { + DocumentDir: () => jest.fn(), + CacheDir: () => jest.fn(), + }, +}));