From b34f72b1b68a7821dedfc66b6a496662f8d58450 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 4 Dec 2021 17:06:36 +0800 Subject: [PATCH] test: fix ci warnings (#33160) --- .../__snapshots__/index.test.tsx.snap | 297 ++++++++++++++---- components/alert/__tests__/index.test.tsx | 15 +- .../__snapshots__/index.test.js.snap | 34 +- .../auto-complete/__tests__/index.test.js | 2 +- components/avatar/__tests__/Avatar.test.js | 4 +- .../__snapshots__/Avatar.test.js.snap | 17 +- .../__snapshots__/index.test.js.snap | 4 +- .../__snapshots__/index.test.tsx.snap | 64 +--- components/button/__tests__/index.test.tsx | 40 +-- .../__snapshots__/index.test.js.snap | 22 +- .../__snapshots__/index.test.js.snap | 2 +- .../__snapshots__/index.test.js.snap | 11 +- .../__snapshots__/checkbox.test.js.snap | 1 + components/comment/__tests__/index.test.js | 2 +- .../config-provider/__tests__/form.test.js | 2 +- .../config-provider/__tests__/index.test.js | 2 +- .../date-picker/__tests__/RangePicker.test.js | 2 +- .../__snapshots__/RangePicker.test.js.snap | 20 +- .../__snapshots__/mount.test.js.snap | 2 +- .../__snapshots__/index.test.js.snap | 8 +- components/dropdown/__tests__/index.test.js | 4 +- components/form/__tests__/index.test.js | 4 +- .../__snapshots__/index.test.js.snap | 2 +- .../__snapshots__/index.test.js.snap | 5 +- .../__snapshots__/index.test.js.snap | 8 +- components/progress/__tests__/index.test.js | 2 +- .../__snapshots__/radio.test.js.snap | 2 + .../__snapshots__/index.test.js.snap | 11 +- .../__snapshots__/index.test.js.snap | 4 +- .../__snapshots__/index.test.js.snap | 4 +- .../__snapshots__/index.test.js.snap | 2 +- .../__snapshots__/Table.test.js.snap | 2 +- .../__snapshots__/index.test.js.snap | 60 +++- components/tabs/__tests__/index.test.js | 20 +- .../__snapshots__/index.test.js.snap | 18 ++ .../__tests__/__snapshots__/list.test.js.snap | 4 + components/transfer/__tests__/index.test.js | 8 +- components/transfer/__tests__/list.test.js | 2 +- components/transfer/__tests__/search.test.js | 4 +- .../__snapshots__/index.test.js.snap | 11 +- .../__snapshots__/directory.test.js.snap | 16 +- .../__snapshots__/upload.test.js.snap | 4 +- site/bisheng.config.js | 1 + tests/matchers/rendered-snapshot.ts | 21 -- tests/setupAfterEnv.ts | 4 - tests/shared/rtlTest.tsx | 2 +- typings/jest.d.ts | 1 - 47 files changed, 478 insertions(+), 299 deletions(-) delete mode 100644 tests/matchers/rendered-snapshot.ts diff --git a/components/alert/__tests__/__snapshots__/index.test.tsx.snap b/components/alert/__tests__/__snapshots__/index.test.tsx.snap index d07a3c448e..1323b431c7 100644 --- a/components/alert/__tests__/__snapshots__/index.test.tsx.snap +++ b/components/alert/__tests__/__snapshots__/index.test.tsx.snap @@ -1,77 +1,238 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Alert action of Alert custom action 1`] = ` - + + + + + + + + + +
+
+ Success Tips +
+
+
+ + +
+ + + + + `; exports[`Alert could accept none react element icon 1`] = ` diff --git a/components/alert/__tests__/index.test.tsx b/components/alert/__tests__/index.test.tsx index e27eeb2c5c..e30928f297 100644 --- a/components/alert/__tests__/index.test.tsx +++ b/components/alert/__tests__/index.test.tsx @@ -1,5 +1,6 @@ import React from 'react'; -import { mount, render } from 'enzyme'; +import { mount } from 'enzyme'; +import { act } from 'react-dom/test-utils'; import Alert from '..'; import Button from '../../button'; import Tooltip from '../../tooltip'; @@ -32,14 +33,18 @@ describe('Alert', () => { onClose={onClose} />, ); - wrapper.find('.ant-alert-close-icon').simulate('click'); - jest.runAllTimers(); + act(() => { + jest.useFakeTimers(); + wrapper.find('.ant-alert-close-icon').simulate('click'); + jest.runAllTimers(); + jest.useRealTimers(); + }); expect(onClose).toHaveBeenCalled(); }); describe('action of Alert', () => { it('custom action', () => { - const wrapper = render( + const wrapper = mount( { it('could accept none react element icon', () => { const wrapper = mount(); - expect(wrapper).toMatchRenderedSnapshot(); + expect(wrapper.render()).toMatchSnapshot(); }); it('should not render message div when no message', () => { diff --git a/components/auto-complete/__tests__/__snapshots__/index.test.js.snap b/components/auto-complete/__tests__/__snapshots__/index.test.js.snap index fa28dcb969..0d8ed77941 100644 --- a/components/auto-complete/__tests__/__snapshots__/index.test.js.snap +++ b/components/auto-complete/__tests__/__snapshots__/index.test.js.snap @@ -11,14 +11,15 @@ exports[`AutoComplete legacy dataSource should accept react element option 1`] = class="ant-select-selection-search" >
key @@ -50,20 +51,20 @@ exports[`AutoComplete legacy dataSource should accept react element option 1`] =
@@ -99,13 +100,14 @@ exports[`AutoComplete rtl render component should be rendered correctly in RTL d class="ant-select-selection-search" > { it('legacy dataSource should accept react element option', () => { const wrapper = mount(ReactNode]} />); - expect(wrapper).toMatchRenderedSnapshot(); + expect(wrapper.render()).toMatchSnapshot(); }); it('legacy AutoComplete.Option should be compatiable', () => { diff --git a/components/avatar/__tests__/Avatar.test.js b/components/avatar/__tests__/Avatar.test.js index aa066fdf7a..a65782dba0 100644 --- a/components/avatar/__tests__/Avatar.test.js +++ b/components/avatar/__tests__/Avatar.test.js @@ -155,7 +155,7 @@ describe('Avatar Render', () => { it('support size is number', () => { const wrapper = mount(TestString); - expect(wrapper).toMatchRenderedSnapshot(); + expect(wrapper.render()).toMatchSnapshot(); }); Object.entries(sizes).forEach(([key, value]) => { @@ -189,7 +189,7 @@ describe('Avatar Render', () => { ); wrapper.find('img').simulate('error'); wrapper.update(); - expect(wrapper).toMatchRenderedSnapshot(); + expect(wrapper.render()).toMatchSnapshot(); wrapper.detach(); global.document.body.removeChild(div); }); diff --git a/components/avatar/__tests__/__snapshots__/Avatar.test.js.snap b/components/avatar/__tests__/__snapshots__/Avatar.test.js.snap index 66ab85ed28..8d66c5c98f 100644 --- a/components/avatar/__tests__/__snapshots__/Avatar.test.js.snap +++ b/components/avatar/__tests__/__snapshots__/Avatar.test.js.snap @@ -86,11 +86,14 @@ exports[`Avatar Render adjusts component size to 100 when window size is xxl 1`] exports[`Avatar Render fallback 1`] = ` - + + A + `; @@ -100,7 +103,7 @@ exports[`Avatar Render rtl render component should be rendered correctly in RTL > `; @@ -229,11 +232,11 @@ exports[`Avatar Render should show image on success after a failure state 2`] = exports[`Avatar Render support size is number 1`] = ` TestString diff --git a/components/badge/__tests__/__snapshots__/index.test.js.snap b/components/badge/__tests__/__snapshots__/index.test.js.snap index d9155ad6c4..d21432a4c6 100644 --- a/components/badge/__tests__/__snapshots__/index.test.js.snap +++ b/components/badge/__tests__/__snapshots__/index.test.js.snap @@ -173,12 +173,12 @@ exports[`Badge rtl render component should be rendered correctly in RTL directio - - - - - 按钮 - - + `; exports[`Button renders Chinese characters correctly 4`] = ` - + 按钮 + `; exports[`Button renders Chinese characters correctly 5`] = ` @@ -169,10 +124,11 @@ exports[`Button renders Chinese characters correctly 6`] = ` > { rtlTest(() => ); it('renders correctly', () => { - expect().toMatchRenderedSnapshot(); + expect(mount().render()).toMatchSnapshot(); }); it('mount correctly', () => { @@ -47,33 +47,37 @@ describe('Button', () => { }); it('renders Chinese characters correctly', () => { - expect().toMatchRenderedSnapshot(); + expect(mount().render()).toMatchSnapshot(); // should not insert space when there is icon - expect(}>按钮).toMatchRenderedSnapshot(); + expect(mount(}>按钮).render()).toMatchSnapshot(); // should not insert space when there is icon expect( , - ).toMatchRenderedSnapshot(); + ).toMatchSnapshot(); // should not insert space when there is icon - expect(}>按钮).toMatchRenderedSnapshot(); + expect(}>按钮).toMatchSnapshot(); // should not insert space when there is icon while loading expect( - } loading> - 按钮 - , - ).toMatchRenderedSnapshot(); + mount( + } loading> + 按钮 + , + ).render(), + ).toMatchSnapshot(); // should insert space while loading - expect().toMatchRenderedSnapshot(); + expect(mount().render()).toMatchSnapshot(); // should insert space while only one nested element expect( - 按钮 - , - ).toMatchRenderedSnapshot(); + mount( + , + ).render(), + ).toMatchSnapshot(); }); it('renders Chinese characters correctly in HOC', () => { @@ -206,9 +210,9 @@ describe('Button', () => { }); it('fixbug renders {0} , 0 and {false}', () => { - expect().toMatchRenderedSnapshot(); - expect().toMatchRenderedSnapshot(); - expect().toMatchRenderedSnapshot(); + expect(mount().render()).toMatchSnapshot(); + expect(mount().render()).toMatchSnapshot(); + expect(mount().render()).toMatchSnapshot(); }); it('should not render as link button when href is undefined', async () => { @@ -320,6 +324,6 @@ describe('Button', () => { <>text , ); - expect(wrapper).toMatchRenderedSnapshot(); + expect(wrapper.render()).toMatchSnapshot(); }); }); diff --git a/components/calendar/__tests__/__snapshots__/index.test.js.snap b/components/calendar/__tests__/__snapshots__/index.test.js.snap index 3cb53bd857..3182f3e41c 100644 --- a/components/calendar/__tests__/__snapshots__/index.test.js.snap +++ b/components/calendar/__tests__/__snapshots__/index.test.js.snap @@ -1905,16 +1905,17 @@ exports[`Calendar rtl render component should be rendered correctly in RTL direc class="ant-select-selection-search" >
diff --git a/components/cascader/__tests__/__snapshots__/index.test.js.snap b/components/cascader/__tests__/__snapshots__/index.test.js.snap index 4385c69659..87bf5ca963 100644 --- a/components/cascader/__tests__/__snapshots__/index.test.js.snap +++ b/components/cascader/__tests__/__snapshots__/index.test.js.snap @@ -1264,16 +1264,17 @@ exports[`Cascader rtl render component should be rendered correctly in RTL direc class="ant-select-selection-search" > { datetime="YYYY-MM-DD HH:mm:ss" />, ); - expect(wrapper).toMatchRenderedSnapshot(); + expect(wrapper.render()).toMatchSnapshot(); }); }); diff --git a/components/config-provider/__tests__/form.test.js b/components/config-provider/__tests__/form.test.js index f5617ce56d..71d1204a9b 100644 --- a/components/config-provider/__tests__/form.test.js +++ b/components/config-provider/__tests__/form.test.js @@ -88,7 +88,7 @@ describe('ConfigProvider.Form', () => { , ); - expect(wrapper).toMatchRenderedSnapshot(); + expect(wrapper.render()).toMatchSnapshot(); }); }); }); diff --git a/components/config-provider/__tests__/index.test.js b/components/config-provider/__tests__/index.test.js index 83f93d9aca..4b11c42a30 100644 --- a/components/config-provider/__tests__/index.test.js +++ b/components/config-provider/__tests__/index.test.js @@ -113,6 +113,6 @@ describe('ConfigProvider', () => { , ); - expect(wrapper).toMatchRenderedSnapshot(); + expect(wrapper.render()).toMatchSnapshot(); }); }); diff --git a/components/date-picker/__tests__/RangePicker.test.js b/components/date-picker/__tests__/RangePicker.test.js index bd890d5e5e..26a347abef 100644 --- a/components/date-picker/__tests__/RangePicker.test.js +++ b/components/date-picker/__tests__/RangePicker.test.js @@ -87,7 +87,7 @@ describe('RangePicker', () => { open />, ); - expect(wrapper).toMatchRenderedSnapshot(); + expect(wrapper.render()).toMatchSnapshot(); }); }); diff --git a/components/date-picker/__tests__/__snapshots__/RangePicker.test.js.snap b/components/date-picker/__tests__/__snapshots__/RangePicker.test.js.snap index 23e2cc902b..250e9bbec6 100644 --- a/components/date-picker/__tests__/__snapshots__/RangePicker.test.js.snap +++ b/components/date-picker/__tests__/__snapshots__/RangePicker.test.js.snap @@ -118,7 +118,7 @@ Array [
,
,
menu @@ -31,8 +31,8 @@ Array [ ,
string diff --git a/components/dropdown/__tests__/index.test.js b/components/dropdown/__tests__/index.test.js index bb991dfd85..06631ea92a 100644 --- a/components/dropdown/__tests__/index.test.js +++ b/components/dropdown/__tests__/index.test.js @@ -25,7 +25,7 @@ describe('Dropdown', () => { , ); - expect(wrapper).toMatchRenderedSnapshot(); + expect(wrapper.render()).toMatchSnapshot(); }); it('overlay is string', () => { @@ -34,7 +34,7 @@ describe('Dropdown', () => { , ); - expect(wrapper).toMatchRenderedSnapshot(); + expect(wrapper.render()).toMatchSnapshot(); }); it('support Menu expandIcon', async () => { diff --git a/components/form/__tests__/index.test.js b/components/form/__tests__/index.test.js index b741fbc473..bf6432db3e 100644 --- a/components/form/__tests__/index.test.js +++ b/components/form/__tests__/index.test.js @@ -796,7 +796,7 @@ describe('Form', () => { , ); - expect(wrapper).toMatchRenderedSnapshot(); + expect(wrapper.render()).toMatchSnapshot(); }); it('noStyle should not work when hidden', () => { @@ -807,7 +807,7 @@ describe('Form', () => { , ); - expect(wrapper).toMatchRenderedSnapshot(); + expect(wrapper.render()).toMatchSnapshot(); }); }); diff --git a/components/layout/__tests__/__snapshots__/index.test.js.snap b/components/layout/__tests__/__snapshots__/index.test.js.snap index c449351cd4..80c2074bd1 100644 --- a/components/layout/__tests__/__snapshots__/index.test.js.snap +++ b/components/layout/__tests__/__snapshots__/index.test.js.snap @@ -28,7 +28,7 @@ exports[`Layout rtl render component should be rendered correctly in RTL directi exports[`Layout rtl render component should be rendered correctly in RTL direction 3`] = `