From a51f7a0508b6152fca8c5078711cedca078864b7 Mon Sep 17 00:00:00 2001 From: afc163 Date: Mon, 26 Aug 2019 22:53:20 +0800 Subject: [PATCH] :white_check_mark: test unmount --- components/auto-complete/__tests__/index.test.js | 3 +++ components/avatar/__tests__/Avatar.test.js | 3 +++ components/back-top/__tests__/index.test.js | 10 +++------- components/badge/__tests__/index.test.js | 3 +++ .../breadcrumb/__tests__/Breadcrumb.test.js | 3 +++ components/button/__tests__/index.test.js | 3 +++ components/calendar/Header.tsx | 4 ++-- components/calendar/__tests__/index.test.js | 4 ++++ components/card/__tests__/index.test.js | 3 +++ components/carousel/__tests__/index.test.js | 3 +++ components/cascader/__tests__/index.test.js | 2 ++ components/checkbox/__tests__/checkbox.test.js | 2 ++ components/checkbox/__tests__/group.test.js | 3 +++ components/collapse/__tests__/index.test.js | 3 +++ components/comment/__tests__/index.test.js | 6 ++++++ .../config-provider/__tests__/index.test.js | 3 +++ components/date-picker/__tests__/mount.test.js | 11 +++++++++++ components/descriptions/__tests__/index.test.js | 3 +++ components/divider/__tests__/index.test.js | 6 ++++++ components/drawer/__tests__/Drawer.test.js | 3 +++ .../dropdown/__tests__/dropdown-button.test.js | 4 ++++ components/empty/__tests__/index.test.js | 3 +++ components/form/__tests__/index.test.js | 4 ++++ components/grid/__tests__/index.test.js | 4 ++++ components/icon/__tests__/index.test.js | 3 +++ components/input-number/__tests__/index.test.js | 2 ++ components/input/__tests__/Password.test.js | 10 ++-------- components/input/__tests__/Search.test.js | 2 ++ components/input/__tests__/index.test.js | 2 ++ components/layout/__tests__/index.test.js | 5 +++++ components/list/__tests__/index.test.js | 8 +++++--- .../locale-provider/__tests__/index.test.js | 3 +++ components/mention/__tests__/index.test.js | 3 +++ components/mentions/__tests__/index.test.js | 2 ++ components/menu/__tests__/index.test.js | 3 +++ components/modal/__tests__/Modal.test.js | 3 +++ components/page-header/__tests__/index.test.js | 3 +++ components/pagination/__tests__/index.test.js | 6 ++++++ components/popconfirm/__tests__/index.test.js | 3 +++ components/popover/__tests__/index.test.js | 3 +++ components/progress/__tests__/index.test.js | 3 +++ .../__tests__/__snapshots__/group.test.js.snap | 2 +- components/radio/__tests__/group.test.js | 2 +- components/radio/__tests__/radio.test.js | 6 +++++- components/rate/__tests__/index.test.js | 2 ++ components/result/__tests__/index.test.js | 5 ++++- components/select/__tests__/index.test.js | 2 ++ components/skeleton/__tests__/index.test.js | 3 +++ components/slider/__tests__/index.test.js | 3 +++ components/spin/__tests__/index.test.js | 3 +++ components/statistic/__tests__/index.test.js | 4 ++++ components/steps/__tests__/index.test.js | 6 ++++++ components/switch/__tests__/index.test.js | 2 ++ components/table/__tests__/Table.test.js | 3 +++ components/tabs/__tests__/index.test.js | 3 +++ components/tag/__tests__/index.test.js | 3 +++ components/time-picker/__tests__/index.test.js | 2 ++ components/timeline/__tests__/index.test.js | 4 ++++ components/tooltip/__tests__/tooltip.test.js | 3 +++ components/transfer/__tests__/index.test.js | 3 +++ components/tree-select/__tests__/index.test.js | 2 ++ components/tree/__tests__/directory.test.js | 4 ++++ components/typography/__tests__/index.test.js | 5 +++++ components/upload/__tests__/upload.test.js | 4 ++++ tests/shared/mountTest.js | 15 +++++++++++++++ 65 files changed, 227 insertions(+), 24 deletions(-) create mode 100644 components/comment/__tests__/index.test.js create mode 100644 components/date-picker/__tests__/mount.test.js create mode 100644 components/divider/__tests__/index.test.js create mode 100644 components/pagination/__tests__/index.test.js create mode 100644 components/steps/__tests__/index.test.js create mode 100644 tests/shared/mountTest.js diff --git a/components/auto-complete/__tests__/index.test.js b/components/auto-complete/__tests__/index.test.js index 95a1814864..3fa0454ca4 100644 --- a/components/auto-complete/__tests__/index.test.js +++ b/components/auto-complete/__tests__/index.test.js @@ -1,8 +1,11 @@ import React from 'react'; import { mount } from 'enzyme'; import AutoComplete from '..'; +import mountTest from '../../../tests/shared/mountTest'; describe('AutoComplete with Custom Input Element Render', () => { + mountTest(AutoComplete); + it('AutoComplete with custom Input render perfectly', () => { const wrapper = mount( diff --git a/components/avatar/__tests__/Avatar.test.js b/components/avatar/__tests__/Avatar.test.js index 18ccd9ab8c..906ed81917 100644 --- a/components/avatar/__tests__/Avatar.test.js +++ b/components/avatar/__tests__/Avatar.test.js @@ -1,8 +1,11 @@ import React from 'react'; import { mount } from 'enzyme'; import Avatar from '..'; +import mountTest from '../../../tests/shared/mountTest'; describe('Avatar Render', () => { + mountTest(Avatar); + let originOffsetWidth; beforeAll(() => { // Mock offsetHeight diff --git a/components/back-top/__tests__/index.test.js b/components/back-top/__tests__/index.test.js index cc61db6426..6029049d06 100644 --- a/components/back-top/__tests__/index.test.js +++ b/components/back-top/__tests__/index.test.js @@ -1,9 +1,12 @@ import React from 'react'; import { mount } from 'enzyme'; import { sleep } from '../../../tests/utils'; +import mountTest from '../../../tests/shared/mountTest'; import BackTop from '..'; describe('BackTop', () => { + mountTest(BackTop); + it('should scroll to top after click it', async () => { const wrapper = mount(); const scrollToSpy = jest.spyOn(window, 'scrollTo').mockImplementation((x, y) => { @@ -20,13 +23,6 @@ describe('BackTop', () => { scrollToSpy.mockRestore(); }); - it('could be unmount without error', async () => { - const wrapper = mount(); - expect(() => { - wrapper.unmount(); - }).not.toThrow(); - }); - it('support onClick', async () => { const onClick = jest.fn(); const wrapper = mount(); diff --git a/components/badge/__tests__/index.test.js b/components/badge/__tests__/index.test.js index d827b711fa..b278e19d50 100644 --- a/components/badge/__tests__/index.test.js +++ b/components/badge/__tests__/index.test.js @@ -2,8 +2,11 @@ import React from 'react'; import { mount, render } from 'enzyme'; import Badge from '../index'; import Tooltip from '../../tooltip'; +import mountTest from '../../../tests/shared/mountTest'; describe('Badge', () => { + mountTest(Badge); + beforeEach(() => { jest.useFakeTimers(); }); diff --git a/components/breadcrumb/__tests__/Breadcrumb.test.js b/components/breadcrumb/__tests__/Breadcrumb.test.js index 83f626c688..7275530ab2 100644 --- a/components/breadcrumb/__tests__/Breadcrumb.test.js +++ b/components/breadcrumb/__tests__/Breadcrumb.test.js @@ -1,8 +1,11 @@ import React from 'react'; import { mount, render } from 'enzyme'; import Breadcrumb from '../index'; +import mountTest from '../../../tests/shared/mountTest'; describe('Breadcrumb', () => { + mountTest(Breadcrumb); + const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); afterEach(() => { diff --git a/components/button/__tests__/index.test.js b/components/button/__tests__/index.test.js index 4dea37683c..c3a4663867 100644 --- a/components/button/__tests__/index.test.js +++ b/components/button/__tests__/index.test.js @@ -3,8 +3,11 @@ import { render, mount } from 'enzyme'; import renderer from 'react-test-renderer'; import Button from '..'; import Icon from '../../icon'; +import mountTest from '../../../tests/shared/mountTest'; describe('Button', () => { + mountTest(Button); + it('renders correctly', () => { const wrapper = render(); expect(wrapper).toMatchSnapshot(); diff --git a/components/calendar/Header.tsx b/components/calendar/Header.tsx index 525496509f..be8b2c0a98 100644 --- a/components/calendar/Header.tsx +++ b/components/calendar/Header.tsx @@ -49,7 +49,7 @@ export default class Header extends React.Component { private calenderHeaderNode: HTMLDivElement; getYearSelectElement(prefixCls: string, year: number) { - const { yearSelectOffset, yearSelectTotal, locale, fullscreen, validRange } = this.props; + const { yearSelectOffset, yearSelectTotal, locale = {}, fullscreen, validRange } = this.props; let start = year - (yearSelectOffset as number); let end = start + (yearSelectTotal as number); if (validRange) { @@ -171,7 +171,7 @@ export default class Header extends React.Component { }; getTypeSwitch = () => { - const { locale, type, fullscreen } = this.props; + const { locale = {}, type, fullscreen } = this.props; const size = fullscreen ? 'default' : 'small'; return ( diff --git a/components/calendar/__tests__/index.test.js b/components/calendar/__tests__/index.test.js index 10fae3caeb..ac6e1e35bd 100644 --- a/components/calendar/__tests__/index.test.js +++ b/components/calendar/__tests__/index.test.js @@ -7,8 +7,12 @@ import Header from '../Header'; import Select from '../../select'; import Group from '../../radio/group'; import Button from '../../radio/radioButton'; +import mountTest from '../../../tests/shared/mountTest'; describe('Calendar', () => { + mountTest(Calendar); + mountTest(() =>
); + it('Calendar should be selectable', () => { const onSelect = jest.fn(); const wrapper = mount(); diff --git a/components/card/__tests__/index.test.js b/components/card/__tests__/index.test.js index dd35ff63e9..e615798264 100644 --- a/components/card/__tests__/index.test.js +++ b/components/card/__tests__/index.test.js @@ -2,8 +2,11 @@ import React from 'react'; import { mount } from 'enzyme'; import Card from '../index'; import Button from '../../button/index'; +import mountTest from '../../../tests/shared/mountTest'; describe('Card', () => { + mountTest(Card); + beforeAll(() => { jest.useFakeTimers(); }); diff --git a/components/carousel/__tests__/index.test.js b/components/carousel/__tests__/index.test.js index e5a7407b08..82879af43b 100644 --- a/components/carousel/__tests__/index.test.js +++ b/components/carousel/__tests__/index.test.js @@ -1,8 +1,11 @@ import React from 'react'; import { mount } from 'enzyme'; import Carousel from '..'; +import mountTest from '../../../tests/shared/mountTest'; describe('Carousel', () => { + mountTest(Carousel); + beforeEach(() => { jest.useFakeTimers(); }); diff --git a/components/cascader/__tests__/index.test.js b/components/cascader/__tests__/index.test.js index 3ead216893..83cc6c16e9 100644 --- a/components/cascader/__tests__/index.test.js +++ b/components/cascader/__tests__/index.test.js @@ -3,6 +3,7 @@ import { render, mount } from 'enzyme'; import KeyCode from 'rc-util/lib/KeyCode'; import Cascader from '..'; import focusTest from '../../../tests/shared/focusTest'; +import mountTest from '../../../tests/shared/mountTest'; const options = [ { @@ -45,6 +46,7 @@ function filter(inputValue, path) { describe('Cascader', () => { focusTest(Cascader); + mountTest(Cascader); it('popup correctly when panel is hidden', () => { const wrapper = mount(); diff --git a/components/checkbox/__tests__/checkbox.test.js b/components/checkbox/__tests__/checkbox.test.js index 4074176851..f3bf80bc62 100644 --- a/components/checkbox/__tests__/checkbox.test.js +++ b/components/checkbox/__tests__/checkbox.test.js @@ -3,9 +3,11 @@ import { mount } from 'enzyme'; import Checkbox from '..'; import focusTest from '../../../tests/shared/focusTest'; import { resetWarned } from '../../_util/warning'; +import mountTest from '../../../tests/shared/mountTest'; describe('Checkbox', () => { focusTest(Checkbox); + mountTest(Checkbox); it('responses hover events', () => { const onMouseEnter = jest.fn(); diff --git a/components/checkbox/__tests__/group.test.js b/components/checkbox/__tests__/group.test.js index fed5154d30..45d3340d3b 100644 --- a/components/checkbox/__tests__/group.test.js +++ b/components/checkbox/__tests__/group.test.js @@ -1,8 +1,11 @@ import React from 'react'; import { mount, render } from 'enzyme'; import Checkbox from '../index'; +import mountTest from '../../../tests/shared/mountTest'; describe('CheckboxGroup', () => { + mountTest(Checkbox.Group); + it('should work basically', () => { const onChange = jest.fn(); const wrapper = mount( diff --git a/components/collapse/__tests__/index.test.js b/components/collapse/__tests__/index.test.js index 28ef303ba3..41ab35b98f 100644 --- a/components/collapse/__tests__/index.test.js +++ b/components/collapse/__tests__/index.test.js @@ -1,8 +1,11 @@ import React from 'react'; import { mount } from 'enzyme'; import Collapse from '..'; +import mountTest from '../../../tests/shared/mountTest'; describe('Collapse', () => { + mountTest(Collapse); + it('should support remove expandIcon', () => { const wrapper = mount( null}> diff --git a/components/comment/__tests__/index.test.js b/components/comment/__tests__/index.test.js new file mode 100644 index 0000000000..8eb7b8fc37 --- /dev/null +++ b/components/comment/__tests__/index.test.js @@ -0,0 +1,6 @@ +import Comment from '../index'; +import mountTest from '../../../tests/shared/mountTest'; + +describe('Comment', () => { + mountTest(Comment); +}); diff --git a/components/config-provider/__tests__/index.test.js b/components/config-provider/__tests__/index.test.js index 219fd3cc13..ccb4670cac 100644 --- a/components/config-provider/__tests__/index.test.js +++ b/components/config-provider/__tests__/index.test.js @@ -2,8 +2,11 @@ import React from 'react'; import { mount } from 'enzyme'; import ConfigProvider from '..'; import Button from '../../button'; +import mountTest from '../../../tests/shared/mountTest'; describe('ConfigProvider', () => { + mountTest(() =>
); + it('Content Security Policy', () => { const csp = { nonce: 'test-antd' }; const wrapper = mount( diff --git a/components/date-picker/__tests__/mount.test.js b/components/date-picker/__tests__/mount.test.js new file mode 100644 index 0000000000..80ec394e79 --- /dev/null +++ b/components/date-picker/__tests__/mount.test.js @@ -0,0 +1,11 @@ +import DatePicker from '..'; +import mountTest from '../../../tests/shared/mountTest'; + +const { MonthPicker, WeekPicker, RangePicker } = DatePicker; + +describe('mount', () => { + mountTest(DatePicker); + mountTest(MonthPicker); + mountTest(WeekPicker); + mountTest(RangePicker); +}); diff --git a/components/descriptions/__tests__/index.test.js b/components/descriptions/__tests__/index.test.js index b90139a3a7..0081f09cc4 100644 --- a/components/descriptions/__tests__/index.test.js +++ b/components/descriptions/__tests__/index.test.js @@ -2,6 +2,7 @@ import React from 'react'; import MockDate from 'mockdate'; import { mount } from 'enzyme'; import Descriptions from '..'; +import mountTest from '../../../tests/shared/mountTest'; jest.mock('enquire.js', () => { let that; @@ -22,6 +23,8 @@ jest.mock('enquire.js', () => { }); describe('Descriptions', () => { + mountTest(Descriptions); + const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); afterEach(() => { diff --git a/components/divider/__tests__/index.test.js b/components/divider/__tests__/index.test.js new file mode 100644 index 0000000000..59763af9a4 --- /dev/null +++ b/components/divider/__tests__/index.test.js @@ -0,0 +1,6 @@ +import Divider from '..'; +import mountTest from '../../../tests/shared/mountTest'; + +describe('Divider', () => { + mountTest(Divider); +}); diff --git a/components/drawer/__tests__/Drawer.test.js b/components/drawer/__tests__/Drawer.test.js index ce30559217..6eecc5e657 100644 --- a/components/drawer/__tests__/Drawer.test.js +++ b/components/drawer/__tests__/Drawer.test.js @@ -1,8 +1,11 @@ import React from 'react'; import { render } from 'enzyme'; import Drawer from '..'; +import mountTest from '../../../tests/shared/mountTest'; describe('Drawer', () => { + mountTest(Drawer); + it('render correctly', () => { const wrapper = render( diff --git a/components/dropdown/__tests__/dropdown-button.test.js b/components/dropdown/__tests__/dropdown-button.test.js index c5684eb4d7..9a80e42fda 100644 --- a/components/dropdown/__tests__/dropdown-button.test.js +++ b/components/dropdown/__tests__/dropdown-button.test.js @@ -2,8 +2,12 @@ import React from 'react'; import { mount } from 'enzyme'; import Dropdown from '..'; import Menu from '../../menu'; +import mountTest from '../../../tests/shared/mountTest'; describe('DropdownButton', () => { + mountTest(() => }>); + mountTest(Dropdown.Button); + it('pass appropriate props to Dropdown', () => { const props = { align: { diff --git a/components/empty/__tests__/index.test.js b/components/empty/__tests__/index.test.js index a883a7cd20..c5f851b88b 100644 --- a/components/empty/__tests__/index.test.js +++ b/components/empty/__tests__/index.test.js @@ -1,8 +1,11 @@ import React from 'react'; import { mount } from 'enzyme'; import Empty from '..'; +import mountTest from '../../../tests/shared/mountTest'; describe('Empty', () => { + mountTest(Empty); + it('image size should change', () => { const wrapper = mount(); expect(wrapper.find('.ant-empty-image').props().style.height).toBe(20); diff --git a/components/form/__tests__/index.test.js b/components/form/__tests__/index.test.js index fd21de5b72..a4b8adabfd 100644 --- a/components/form/__tests__/index.test.js +++ b/components/form/__tests__/index.test.js @@ -2,8 +2,12 @@ import React from 'react'; import { mount } from 'enzyme'; import Form from '..'; +import mountTest from '../../../tests/shared/mountTest'; describe('Form', () => { + mountTest(Form); + mountTest(Form.Item); + it('hideRequiredMark', () => { const wrapper = mount(
); expect(wrapper.find('form').hasClass('ant-form-hide-required-mark')).toBe(true); diff --git a/components/grid/__tests__/index.test.js b/components/grid/__tests__/index.test.js index 3aeadcf53d..a2a7b78c77 100644 --- a/components/grid/__tests__/index.test.js +++ b/components/grid/__tests__/index.test.js @@ -1,6 +1,7 @@ import React from 'react'; import { render, mount } from 'enzyme'; import { Col, Row } from '..'; +import mountTest from '../../../tests/shared/mountTest'; jest.mock('enquire.js', () => { let that; @@ -21,6 +22,9 @@ jest.mock('enquire.js', () => { }); describe('Grid', () => { + mountTest(Row); + mountTest(Col); + it('should render Col', () => { const wrapper = render(); expect(wrapper).toMatchSnapshot(); diff --git a/components/icon/__tests__/index.test.js b/components/icon/__tests__/index.test.js index 43eb7beb1f..90f2762eec 100644 --- a/components/icon/__tests__/index.test.js +++ b/components/icon/__tests__/index.test.js @@ -4,8 +4,11 @@ import ReactIcon from '@ant-design/icons-react'; import Icon from '..'; import Tooltip from '../../tooltip'; import { getThemeFromTypeName, withThemeSuffix } from '../utils'; +import mountTest from '../../../tests/shared/mountTest'; describe('Icon', () => { + mountTest(Icon); + it('should render to a ...', () => { const wrapper = render(); expect(wrapper).toMatchSnapshot(); diff --git a/components/input-number/__tests__/index.test.js b/components/input-number/__tests__/index.test.js index d62de9e242..7bce307f5f 100644 --- a/components/input-number/__tests__/index.test.js +++ b/components/input-number/__tests__/index.test.js @@ -2,9 +2,11 @@ import React from 'react'; import { mount } from 'enzyme'; import InputNumber from '..'; import focusTest from '../../../tests/shared/focusTest'; +import mountTest from '../../../tests/shared/mountTest'; describe('InputNumber', () => { focusTest(InputNumber); + mountTest(InputNumber); // https://github.com/ant-design/ant-design/issues/13896 it('should return null when blur a empty input number', () => { diff --git a/components/input/__tests__/Password.test.js b/components/input/__tests__/Password.test.js index 5e51ffd56d..3bbce297ed 100644 --- a/components/input/__tests__/Password.test.js +++ b/components/input/__tests__/Password.test.js @@ -3,9 +3,11 @@ import { mount } from 'enzyme'; // eslint-disable-next-line import/no-unresolved import Input from '..'; import focusTest from '../../../tests/shared/focusTest'; +import mountTest from '../../../tests/shared/mountTest'; describe('Input.Password', () => { focusTest(Input.Password); + mountTest(Input.Password); it('should get input element from ref', () => { const wrapper = mount(); @@ -61,12 +63,4 @@ describe('Input.Password', () => { .getDOMNode(), ); }); - - // https://github.com/ant-design/ant-design/pull/18441 - it('should unmount without error', () => { - const wrapper = mount(); - expect(() => { - wrapper.unmount(); - }).not.toThrow(); - }); }); diff --git a/components/input/__tests__/Search.test.js b/components/input/__tests__/Search.test.js index ef0cef7c52..26c14fbe8a 100644 --- a/components/input/__tests__/Search.test.js +++ b/components/input/__tests__/Search.test.js @@ -3,9 +3,11 @@ import { mount } from 'enzyme'; import Search from '../Search'; import Button from '../../button'; import focusTest from '../../../tests/shared/focusTest'; +import mountTest from '../../../tests/shared/mountTest'; describe('Input.Search', () => { focusTest(Search); + mountTest(Search); it('should support custom button', () => { const wrapper = mount(ok} />); diff --git a/components/input/__tests__/index.test.js b/components/input/__tests__/index.test.js index a16adc405a..459bd474ef 100644 --- a/components/input/__tests__/index.test.js +++ b/components/input/__tests__/index.test.js @@ -4,6 +4,7 @@ import { mount } from 'enzyme'; import Form from '../../form'; import Input from '..'; import focusTest from '../../../tests/shared/focusTest'; +import mountTest from '../../../tests/shared/mountTest'; import calculateNodeHeight, { calculateNodeStyling } from '../calculateNodeHeight'; const { TextArea } = Input; @@ -20,6 +21,7 @@ describe('Input', () => { }); focusTest(Input); + mountTest(Input); it('should support maxLength', () => { const wrapper = mount(); diff --git a/components/layout/__tests__/index.test.js b/components/layout/__tests__/index.test.js index 43a452f4ae..171a67c9aa 100644 --- a/components/layout/__tests__/index.test.js +++ b/components/layout/__tests__/index.test.js @@ -3,10 +3,15 @@ import { mount, render } from 'enzyme'; import Layout from '..'; import Icon from '../../icon'; import Menu from '../../menu'; +import mountTest from '../../../tests/shared/mountTest'; const { Sider, Content } = Layout; describe('Layout', () => { + mountTest(Layout); + mountTest(Content); + mountTest(Sider); + it('detect the sider as children', async () => { const wrapper = mount( diff --git a/components/list/__tests__/index.test.js b/components/list/__tests__/index.test.js index 9bf3316a22..139a612447 100644 --- a/components/list/__tests__/index.test.js +++ b/components/list/__tests__/index.test.js @@ -1,13 +1,15 @@ import React from 'react'; import { mount } from 'enzyme'; import List from '..'; - -const ListItem = List.Item; +import mountTest from '../../../tests/shared/mountTest'; describe('List', () => { + mountTest(List); + mountTest(List.Item); + it('locale not passed to internal div', async () => { const locale = { emptyText: 'Custom text' }; - const renderItem = item => {item}; + const renderItem = item => {item}; const dataSource = []; const wrapper = mount(); diff --git a/components/locale-provider/__tests__/index.test.js b/components/locale-provider/__tests__/index.test.js index 3cda36139a..5bebba8991 100644 --- a/components/locale-provider/__tests__/index.test.js +++ b/components/locale-provider/__tests__/index.test.js @@ -4,6 +4,7 @@ import { mount } from 'enzyme'; import moment from 'moment'; import MockDate from 'mockdate'; import { resetWarned } from '../../_util/warning'; +import mountTest from '../../../tests/shared/mountTest'; import { LocaleProvider, Pagination, @@ -159,6 +160,8 @@ const App = () => ( ); describe('Locale Provider', () => { + mountTest(() =>
); + beforeAll(() => { MockDate.set(moment('2017-09-18T03:30:07.795')); }); diff --git a/components/mention/__tests__/index.test.js b/components/mention/__tests__/index.test.js index 7c81d00b1c..ab4059414c 100644 --- a/components/mention/__tests__/index.test.js +++ b/components/mention/__tests__/index.test.js @@ -1,10 +1,13 @@ import React from 'react'; import { mount } from 'enzyme'; import Mention from '..'; +import mountTest from '../../../tests/shared/mountTest'; const { toContentState } = Mention; describe('Mention', () => { + mountTest(Mention); + beforeAll(() => { jest.useFakeTimers(); }); diff --git a/components/mentions/__tests__/index.test.js b/components/mentions/__tests__/index.test.js index a876171ba1..e99dcbd1d5 100644 --- a/components/mentions/__tests__/index.test.js +++ b/components/mentions/__tests__/index.test.js @@ -2,6 +2,7 @@ import React from 'react'; import { mount } from 'enzyme'; import Mentions from '..'; import focusTest from '../../../tests/shared/focusTest'; +import mountTest from '../../../tests/shared/mountTest'; const { getMentions } = Mentions; @@ -73,6 +74,7 @@ describe('Mentions', () => { }); focusTest(Mentions); + mountTest(Mentions); it('loading', () => { const wrapper = mount(); diff --git a/components/menu/__tests__/index.test.js b/components/menu/__tests__/index.test.js index 1076de172c..5d3b0064fa 100644 --- a/components/menu/__tests__/index.test.js +++ b/components/menu/__tests__/index.test.js @@ -4,6 +4,7 @@ import Menu from '..'; import Icon from '../../icon'; import Layout from '../../layout'; import raf from '../../_util/raf'; +import mountTest from '../../../tests/shared/mountTest'; jest.mock('mutationobserver-shim', () => { global.MutationObserver = function MutationObserver() { @@ -15,6 +16,8 @@ jest.mock('mutationobserver-shim', () => { const { SubMenu } = Menu; describe('Menu', () => { + mountTest(() => ); + beforeEach(() => { jest.useFakeTimers(); }); diff --git a/components/modal/__tests__/Modal.test.js b/components/modal/__tests__/Modal.test.js index c96379deec..40dd919007 100644 --- a/components/modal/__tests__/Modal.test.js +++ b/components/modal/__tests__/Modal.test.js @@ -1,6 +1,7 @@ import React from 'react'; import { mount } from 'enzyme'; import Modal from '..'; +import mountTest from '../../../tests/shared/mountTest'; jest.mock('rc-util/lib/Portal'); @@ -34,6 +35,8 @@ class ModalTester extends React.Component { } describe('Modal', () => { + mountTest(Modal); + it('render correctly', () => { const wrapper = mount(); expect(wrapper.render()).toMatchSnapshot(); diff --git a/components/page-header/__tests__/index.test.js b/components/page-header/__tests__/index.test.js index 4d3f454a80..daf030a1ba 100644 --- a/components/page-header/__tests__/index.test.js +++ b/components/page-header/__tests__/index.test.js @@ -1,8 +1,11 @@ import React from 'react'; import { mount, render } from 'enzyme'; import PageHeader from '..'; +import mountTest from '../../../tests/shared/mountTest'; describe('PageHeader', () => { + mountTest(PageHeader); + it('pageHeader should not contain back it back', () => { const routes = [ { diff --git a/components/pagination/__tests__/index.test.js b/components/pagination/__tests__/index.test.js new file mode 100644 index 0000000000..cf32ca33c9 --- /dev/null +++ b/components/pagination/__tests__/index.test.js @@ -0,0 +1,6 @@ +import Pagination from '..'; +import mountTest from '../../../tests/shared/mountTest'; + +describe('Pagination', () => { + mountTest(Pagination); +}); diff --git a/components/popconfirm/__tests__/index.test.js b/components/popconfirm/__tests__/index.test.js index 30969efa37..958faece72 100644 --- a/components/popconfirm/__tests__/index.test.js +++ b/components/popconfirm/__tests__/index.test.js @@ -1,8 +1,11 @@ import React from 'react'; import { mount } from 'enzyme'; import Popconfirm from '..'; +import mountTest from '../../../tests/shared/mountTest'; describe('Popconfirm', () => { + mountTest(Popconfirm); + const eventObject = expect.objectContaining({ target: expect.anything(), preventDefault: expect.any(Function), diff --git a/components/popover/__tests__/index.test.js b/components/popover/__tests__/index.test.js index 7d9e89eea2..8036cb8f3e 100644 --- a/components/popover/__tests__/index.test.js +++ b/components/popover/__tests__/index.test.js @@ -1,8 +1,11 @@ import React from 'react'; import { mount } from 'enzyme'; import Popover from '..'; +import mountTest from '../../../tests/shared/mountTest'; describe('Popover', () => { + mountTest(Popover); + it('should show overlay when trigger is clicked', () => { const popover = mount( diff --git a/components/progress/__tests__/index.test.js b/components/progress/__tests__/index.test.js index b172f5c1e5..21bb8e2d8c 100644 --- a/components/progress/__tests__/index.test.js +++ b/components/progress/__tests__/index.test.js @@ -2,8 +2,11 @@ import React from 'react'; import { mount } from 'enzyme'; import Progress from '..'; import { handleGradient, sortGradient } from '../Line'; +import mountTest from '../../../tests/shared/mountTest'; describe('Progress', () => { + mountTest(Progress); + it('successPercent should decide the progress status when it exists', () => { const wrapper = mount(); expect(wrapper.find('.ant-progress-status-success')).toHaveLength(0); diff --git a/components/radio/__tests__/__snapshots__/group.test.js.snap b/components/radio/__tests__/__snapshots__/group.test.js.snap index adda9e9d31..b8cb4e1e38 100644 --- a/components/radio/__tests__/__snapshots__/group.test.js.snap +++ b/components/radio/__tests__/__snapshots__/group.test.js.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Radio passes prefixCls down to radio 1`] = ` +exports[`Radio Group passes prefixCls down to radio 1`] = `
diff --git a/components/radio/__tests__/group.test.js b/components/radio/__tests__/group.test.js index c43978b021..aed23e053c 100644 --- a/components/radio/__tests__/group.test.js +++ b/components/radio/__tests__/group.test.js @@ -4,7 +4,7 @@ import Radio from '../radio'; import RadioGroup from '../group'; import RadioButton from '../radioButton'; -describe('Radio', () => { +describe('Radio Group', () => { function createRadioGroup(props) { return ( diff --git a/components/radio/__tests__/radio.test.js b/components/radio/__tests__/radio.test.js index c3e170b7ff..1fd88a8f2d 100644 --- a/components/radio/__tests__/radio.test.js +++ b/components/radio/__tests__/radio.test.js @@ -1,10 +1,14 @@ import React from 'react'; import { mount, render } from 'enzyme'; -import Radio from '../radio'; +import Radio, { Group, Button } from '..'; import focusTest from '../../../tests/shared/focusTest'; +import mountTest from '../../../tests/shared/mountTest'; describe('Radio', () => { focusTest(Radio); + mountTest(Radio); + mountTest(Group); + mountTest(Button); it('should render correctly', () => { const wrapper = render(Test); diff --git a/components/rate/__tests__/index.test.js b/components/rate/__tests__/index.test.js index 36295752f2..3944c14c4a 100644 --- a/components/rate/__tests__/index.test.js +++ b/components/rate/__tests__/index.test.js @@ -1,6 +1,8 @@ import Rate from '..'; import focusTest from '../../../tests/shared/focusTest'; +import mountTest from '../../../tests/shared/mountTest'; describe('Rate', () => { focusTest(Rate); + mountTest(Rate); }); diff --git a/components/result/__tests__/index.test.js b/components/result/__tests__/index.test.js index 084077fa35..f01a4c4577 100644 --- a/components/result/__tests__/index.test.js +++ b/components/result/__tests__/index.test.js @@ -2,8 +2,11 @@ import React from 'react'; import { mount } from 'enzyme'; import Result from '..'; import Button from '../../button'; +import mountTest from '../../../tests/shared/mountTest'; + +describe('Result', () => { + mountTest(Result); -describe('Progress', () => { it('🙂 successPercent should decide the progress status when it exists', () => { const wrapper = mount( { focusTest(Select); + mountTest(Select); beforeEach(() => { jest.useFakeTimers(); diff --git a/components/skeleton/__tests__/index.test.js b/components/skeleton/__tests__/index.test.js index 287a54ce67..9fb669a586 100644 --- a/components/skeleton/__tests__/index.test.js +++ b/components/skeleton/__tests__/index.test.js @@ -1,6 +1,7 @@ import React from 'react'; import { mount } from 'enzyme'; import Skeleton from '..'; +import mountTest from '../../../tests/shared/mountTest'; describe('Skeleton', () => { const genSkeleton = props => @@ -10,6 +11,8 @@ describe('Skeleton', () => { , ); + mountTest(Skeleton); + describe('avatar', () => { it('size', () => { const wrapperSmall = genSkeleton({ avatar: { size: 'small' } }); diff --git a/components/slider/__tests__/index.test.js b/components/slider/__tests__/index.test.js index 59f8e5d390..1691443ce4 100644 --- a/components/slider/__tests__/index.test.js +++ b/components/slider/__tests__/index.test.js @@ -1,8 +1,11 @@ import React from 'react'; import { render, mount } from 'enzyme'; import Slider from '..'; +import mountTest from '../../../tests/shared/mountTest'; describe('Slider', () => { + mountTest(Slider); + it('should show tooltip when hovering slider handler', () => { const wrapper = mount(); wrapper diff --git a/components/spin/__tests__/index.test.js b/components/spin/__tests__/index.test.js index 68984ab069..f8b1083e34 100644 --- a/components/spin/__tests__/index.test.js +++ b/components/spin/__tests__/index.test.js @@ -1,8 +1,11 @@ import React from 'react'; import { render, mount } from 'enzyme'; import Spin from '..'; +import mountTest from '../../../tests/shared/mountTest'; describe('Spin', () => { + mountTest(Spin); + it('should only affect the spin element when set style to a nested xx', () => { const wrapper = mount( diff --git a/components/statistic/__tests__/index.test.js b/components/statistic/__tests__/index.test.js index affb9003fc..4d989df658 100644 --- a/components/statistic/__tests__/index.test.js +++ b/components/statistic/__tests__/index.test.js @@ -5,8 +5,12 @@ import { mount } from 'enzyme'; import Statistic from '..'; import { formatTimeStr } from '../utils'; import { sleep } from '../../../tests/utils'; +import mountTest from '../../../tests/shared/mountTest'; describe('Statistic', () => { + mountTest(Statistic); + mountTest(Statistic.Countdown); + beforeAll(() => { MockDate.set(moment('2018-11-28 00:00:00')); }); diff --git a/components/steps/__tests__/index.test.js b/components/steps/__tests__/index.test.js new file mode 100644 index 0000000000..6a65541059 --- /dev/null +++ b/components/steps/__tests__/index.test.js @@ -0,0 +1,6 @@ +import Steps from '..'; +import mountTest from '../../../tests/shared/mountTest'; + +describe('Steps', () => { + mountTest(Steps); +}); diff --git a/components/switch/__tests__/index.test.js b/components/switch/__tests__/index.test.js index 3b48c2eebf..17b8dfc019 100644 --- a/components/switch/__tests__/index.test.js +++ b/components/switch/__tests__/index.test.js @@ -3,9 +3,11 @@ import { mount } from 'enzyme'; import Switch from '..'; import focusTest from '../../../tests/shared/focusTest'; import { resetWarned } from '../../_util/warning'; +import mountTest from '../../../tests/shared/mountTest'; describe('Switch', () => { focusTest(Switch); + mountTest(Switch); it('should has click wave effect', async () => { const wrapper = mount(); diff --git a/components/table/__tests__/Table.test.js b/components/table/__tests__/Table.test.js index dd5bb39e72..8c1a880cc0 100644 --- a/components/table/__tests__/Table.test.js +++ b/components/table/__tests__/Table.test.js @@ -1,10 +1,13 @@ import React from 'react'; import { render, shallow, mount } from 'enzyme'; import Table from '..'; +import mountTest from '../../../tests/shared/mountTest'; const { Column, ColumnGroup } = Table; describe('Table', () => { + mountTest(Table); + const warnSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); afterAll(() => { diff --git a/components/tabs/__tests__/index.test.js b/components/tabs/__tests__/index.test.js index 77cad3c172..c1b628410f 100644 --- a/components/tabs/__tests__/index.test.js +++ b/components/tabs/__tests__/index.test.js @@ -1,10 +1,13 @@ import React from 'react'; import { mount, render } from 'enzyme'; import Tabs from '..'; +import mountTest from '../../../tests/shared/mountTest'; const { TabPane } = Tabs; describe('Tabs', () => { + mountTest(() => ); + describe('editable-card', () => { let handleEdit; let wrapper; diff --git a/components/tag/__tests__/index.test.js b/components/tag/__tests__/index.test.js index c272df49cc..407c696511 100644 --- a/components/tag/__tests__/index.test.js +++ b/components/tag/__tests__/index.test.js @@ -1,8 +1,11 @@ import React from 'react'; import { mount } from 'enzyme'; import Tag from '..'; +import mountTest from '../../../tests/shared/mountTest'; describe('Tag', () => { + mountTest(Tag); + beforeAll(() => { jest.useFakeTimers(); }); diff --git a/components/time-picker/__tests__/index.test.js b/components/time-picker/__tests__/index.test.js index 035f7bf2e0..1571b02900 100644 --- a/components/time-picker/__tests__/index.test.js +++ b/components/time-picker/__tests__/index.test.js @@ -4,6 +4,7 @@ import RcTimePicker from 'rc-time-picker/lib/TimePicker'; import moment from 'moment'; import TimePicker from '..'; import focusTest from '../../../tests/shared/focusTest'; +import mountTest from '../../../tests/shared/mountTest'; describe('TimePicker', () => { const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); @@ -17,6 +18,7 @@ describe('TimePicker', () => { }); focusTest(TimePicker); + mountTest(TimePicker); it('renders addon correctly', () => { const addon = () => ; diff --git a/components/timeline/__tests__/index.test.js b/components/timeline/__tests__/index.test.js index 5ab2341900..3ee4aa6d6a 100644 --- a/components/timeline/__tests__/index.test.js +++ b/components/timeline/__tests__/index.test.js @@ -1,6 +1,7 @@ import React from 'react'; import { mount } from 'enzyme'; import TimeLine from '..'; +import mountTest from '../../../tests/shared/mountTest'; const { Item } = TimeLine; @@ -14,6 +15,9 @@ const wrapperFactory = (timeLineProps = {}) => ); describe('TimeLine', () => { + mountTest(TimeLine); + mountTest(TimeLine.Item); + describe('renders items without passing any props correctly', () => { const wrapper = wrapperFactory(); diff --git a/components/tooltip/__tests__/tooltip.test.js b/components/tooltip/__tests__/tooltip.test.js index 8004ba805a..190f905d7b 100644 --- a/components/tooltip/__tests__/tooltip.test.js +++ b/components/tooltip/__tests__/tooltip.test.js @@ -8,8 +8,11 @@ import DatePicker from '../../date-picker'; import Input from '../../input'; import Group from '../../input/Group'; import { sleep } from '../../../tests/utils'; +import mountTest from '../../../tests/shared/mountTest'; describe('Tooltip', () => { + mountTest(Tooltip); + it('check `onVisibleChange` arguments', () => { const onVisibleChange = jest.fn(); diff --git a/components/transfer/__tests__/index.test.js b/components/transfer/__tests__/index.test.js index 7a1ea255cb..4d2261d65e 100644 --- a/components/transfer/__tests__/index.test.js +++ b/components/transfer/__tests__/index.test.js @@ -8,6 +8,7 @@ import TransferSearch from '../search'; import TransferItem from '../ListItem'; import Button from '../../button'; import Checkbox from '../../checkbox'; +import mountTest from '../../../tests/shared/mountTest'; const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); @@ -94,6 +95,8 @@ const searchTransferProps = { }; describe('Transfer', () => { + mountTest(Transfer); + it('should render correctly', () => { const wrapper = render(); expect(wrapper).toMatchSnapshot(); diff --git a/components/tree-select/__tests__/index.test.js b/components/tree-select/__tests__/index.test.js index 5dcf8ef9f2..d6270bcc7d 100644 --- a/components/tree-select/__tests__/index.test.js +++ b/components/tree-select/__tests__/index.test.js @@ -2,9 +2,11 @@ import React from 'react'; import { mount } from 'enzyme'; import TreeSelect from '..'; import focusTest from '../../../tests/shared/focusTest'; +import mountTest from '../../../tests/shared/mountTest'; describe('TreeSelect', () => { focusTest(TreeSelect); + mountTest(TreeSelect); describe('showSearch', () => { it('keep default logic', () => { diff --git a/components/tree/__tests__/directory.test.js b/components/tree/__tests__/directory.test.js index c8ec72061d..116a6a55ff 100644 --- a/components/tree/__tests__/directory.test.js +++ b/components/tree/__tests__/directory.test.js @@ -2,12 +2,16 @@ import React from 'react'; import { mount, render } from 'enzyme'; import debounce from 'lodash/debounce'; import Tree from '../index'; +import mountTest from '../../../tests/shared/mountTest'; const { DirectoryTree, TreeNode } = Tree; jest.mock('lodash/debounce'); describe('Directory Tree', () => { + mountTest(Tree); + mountTest(DirectoryTree); + debounce.mockImplementation(fn => fn); beforeAll(() => { diff --git a/components/typography/__tests__/index.test.js b/components/typography/__tests__/index.test.js index 0c140d6f60..0f83d33e62 100644 --- a/components/typography/__tests__/index.test.js +++ b/components/typography/__tests__/index.test.js @@ -5,10 +5,15 @@ import copy from 'copy-to-clipboard'; import Title from '../Title'; import Paragraph from '../Paragraph'; import Base from '../Base'; // eslint-disable-line import/no-named-as-default +import mountTest from '../../../tests/shared/mountTest'; jest.mock('copy-to-clipboard'); describe('Typography', () => { + mountTest(Paragraph); + mountTest(Base); + mountTest(Title); + const LINE_STR_COUNT = 20; const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); diff --git a/components/upload/__tests__/upload.test.js b/components/upload/__tests__/upload.test.js index 1fd064b06b..483df22595 100644 --- a/components/upload/__tests__/upload.test.js +++ b/components/upload/__tests__/upload.test.js @@ -6,8 +6,12 @@ import Form from '../../form'; import { T, fileToObject, genPercentAdd, getFileItem, removeFileItem } from '../utils'; import { setup, teardown } from './mock'; import { resetWarned } from '../../_util/warning'; +import mountTest from '../../../tests/shared/mountTest'; describe('Upload', () => { + mountTest(Upload); + mountTest(Upload.Dragger); + beforeEach(() => setup()); afterEach(() => teardown()); diff --git a/tests/shared/mountTest.js b/tests/shared/mountTest.js new file mode 100644 index 0000000000..931db4c859 --- /dev/null +++ b/tests/shared/mountTest.js @@ -0,0 +1,15 @@ +import React from 'react'; +import { mount } from 'enzyme'; + +export default function mountTest(Component) { + describe(`mount and unmount`, () => { + // https://github.com/ant-design/ant-design/pull/18441 + it(`component could be updated and unmounted without errors`, () => { + const wrapper = mount(); + expect(() => { + wrapper.setProps({}); + wrapper.unmount(); + }).not.toThrow(); + }); + }); +}