From 059db1a788a0cf4cde3dda0d4fee6851d18ba177 Mon Sep 17 00:00:00 2001 From: Saturnino Abril Date: Fri, 7 Sep 2018 23:05:35 +0800 Subject: [PATCH] fix warnings in running jest test (#2087) --- .../announcement_banner.test.js | 4 +- .../__snapshots__/index.test.js.snap | 2 +- app/components/custom_list/index.test.js | 4 +- app/components/formatted_text.js | 15 +- .../post_list/date_header/date_header.test.js | 4 +- .../show_more_button.test.js.snap | 20 +-- .../show_more_button/show_more_button.test.js | 4 +- .../channel_item/channel_item.test.js | 4 +- .../forgot_password.test.js.snap | 156 +++++++++--------- .../forgot_password/forgot_password.test.js | 4 +- .../more_channels/more_channels.test.js | 4 +- .../__snapshots__/select_team.test.js.snap | 12 +- app/screens/select_team/select_team.test.js | 5 +- ...cation_settings_email.android.test.js.snap | 12 +- ...tification_settings_email.ios.test.js.snap | 4 +- ...otification_settings_email.android.test.js | 3 - .../notification_settings_email.ios.test.js | 4 +- package.json | 1 + test/setup.js | 43 +++++ 19 files changed, 165 insertions(+), 140 deletions(-) create mode 100644 test/setup.js diff --git a/app/components/announcement_banner/announcement_banner.test.js b/app/components/announcement_banner/announcement_banner.test.js index 1dfcc393a..92d59ac51 100644 --- a/app/components/announcement_banner/announcement_banner.test.js +++ b/app/components/announcement_banner/announcement_banner.test.js @@ -2,9 +2,7 @@ // See LICENSE.txt for license information. import React from 'react'; -import {configure, shallow} from 'enzyme'; -import Adapter from 'enzyme-adapter-react-16'; -configure({adapter: new Adapter()}); +import {shallow} from 'enzyme'; import AnnouncementBanner from './announcement_banner.js'; diff --git a/app/components/custom_list/__snapshots__/index.test.js.snap b/app/components/custom_list/__snapshots__/index.test.js.snap index 851c7ac81..d18e08962 100644 --- a/app/components/custom_list/__snapshots__/index.test.js.snap +++ b/app/components/custom_list/__snapshots__/index.test.js.snap @@ -214,7 +214,7 @@ exports[`CustomList should match snapshot, renderFooter 2`] = ` } } > - 0; let nodes; @@ -90,5 +93,3 @@ class FormattedText extends React.PureComponent { return createElement(Text, props, ...nodes); } } - -export default injectIntl(FormattedText); diff --git a/app/components/post_list/date_header/date_header.test.js b/app/components/post_list/date_header/date_header.test.js index e7b9e2898..651c46dfd 100644 --- a/app/components/post_list/date_header/date_header.test.js +++ b/app/components/post_list/date_header/date_header.test.js @@ -4,9 +4,7 @@ /* eslint-disable max-nested-callbacks */ import React from 'react'; -import {configure, shallow} from 'enzyme'; -import Adapter from 'enzyme-adapter-react-16'; -configure({adapter: new Adapter()}); +import {shallow} from 'enzyme'; import DateHeader from './date_header.js'; diff --git a/app/components/show_more_button/__snapshots__/show_more_button.test.js.snap b/app/components/show_more_button/__snapshots__/show_more_button.test.js.snap index 283dae457..1425cfa80 100644 --- a/app/components/show_more_button/__snapshots__/show_more_button.test.js.snap +++ b/app/components/show_more_button/__snapshots__/show_more_button.test.js.snap @@ -12,7 +12,7 @@ exports[`ShowMoreButton should match, button snapshot 1`] = ` > + - - - + - + - + - + , - + - + - + - + , - - - - - , undefined, - - - - - - - , undefined, - - - - - - - , undefined, - - - - - - - , undefined, - - - - - - - , undefined, - - - - - - - , undefined, - - - - - - - } label={ - @@ -45,7 +45,7 @@ exports[`NotificationSettingsEmailAndroid should match snapshot 2`] = ` - - - - @@ -53,7 +53,7 @@ exports[`NotificationSettingsEmailIos should match snapshot, renderEmailSection actionType="select" actionValue="0" label={ - diff --git a/app/screens/settings/notification_settings_email/notification_settings_email.android.test.js b/app/screens/settings/notification_settings_email/notification_settings_email.android.test.js index 8649e6fda..acf8246c7 100644 --- a/app/screens/settings/notification_settings_email/notification_settings_email.android.test.js +++ b/app/screens/settings/notification_settings_email/notification_settings_email.android.test.js @@ -2,9 +2,6 @@ // See LICENSE.txt for license information. import React from 'react'; -import {configure} from 'enzyme'; -import Adapter from 'enzyme-adapter-react-16'; -configure({adapter: new Adapter()}); import {shallowWithIntl} from 'test/intl-test-helper'; import {emptyFunction} from 'app/utils/general'; diff --git a/app/screens/settings/notification_settings_email/notification_settings_email.ios.test.js b/app/screens/settings/notification_settings_email/notification_settings_email.ios.test.js index d2d5fb586..f202aaaec 100644 --- a/app/screens/settings/notification_settings_email/notification_settings_email.ios.test.js +++ b/app/screens/settings/notification_settings_email/notification_settings_email.ios.test.js @@ -2,9 +2,7 @@ // See LICENSE.txt for license information. import React from 'react'; -import {configure, shallow} from 'enzyme'; -import Adapter from 'enzyme-adapter-react-16'; -configure({adapter: new Adapter()}); +import {shallow} from 'enzyme'; import {emptyFunction} from 'app/utils/general'; diff --git a/package.json b/package.json index 050512664..4dea68aad 100644 --- a/package.json +++ b/package.json @@ -125,6 +125,7 @@ "text-summary" ], "preset": "react-native", + "setupTestFrameworkScriptFile": "/test/setup.js", "testPathIgnorePatterns": [ "/node_modules/" ] diff --git a/test/setup.js b/test/setup.js new file mode 100644 index 000000000..eef7a3907 --- /dev/null +++ b/test/setup.js @@ -0,0 +1,43 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import {configure} from 'enzyme'; +import Adapter from 'enzyme-adapter-react-16'; +configure({adapter: new Adapter()}); + +/* eslint-disable no-console */ + +let logs; +let warns; +let errors; +beforeAll(() => { + console.originalLog = console.log; + console.log = jest.fn((...params) => { + console.originalLog(...params); + logs.push(params); + }); + + console.originalWarn = console.warn; + console.warn = jest.fn((...params) => { + console.originalWarn(...params); + warns.push(params); + }); + + console.originalError = console.error; + console.error = jest.fn((...params) => { + console.originalError(...params); + errors.push(params); + }); +}); + +beforeEach(() => { + logs = []; + warns = []; + errors = []; +}); + +afterEach(() => { + if (logs.length > 0 || warns.length > 0 || errors.length > 0) { + throw new Error('Unexpected console logs' + logs + warns + errors); + } +});