mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 02:59:04 +08:00
✅ test unmount
This commit is contained in:
parent
19cc7e7cee
commit
a51f7a0508
@ -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(
|
||||
<AutoComplete dataSource={['12345', '23456', '34567']}>
|
||||
|
@ -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
|
||||
|
@ -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(<BackTop visibilityHeight={-1} />);
|
||||
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(<BackTop />);
|
||||
expect(() => {
|
||||
wrapper.unmount();
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
it('support onClick', async () => {
|
||||
const onClick = jest.fn();
|
||||
const wrapper = mount(<BackTop onClick={onClick} visibilityHeight={-1} />);
|
||||
|
@ -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();
|
||||
});
|
||||
|
@ -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(() => {
|
||||
|
@ -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(<Button>Follow</Button>);
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
|
@ -49,7 +49,7 @@ export default class Header extends React.Component<HeaderProps, any> {
|
||||
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<HeaderProps, any> {
|
||||
};
|
||||
|
||||
getTypeSwitch = () => {
|
||||
const { locale, type, fullscreen } = this.props;
|
||||
const { locale = {}, type, fullscreen } = this.props;
|
||||
const size = fullscreen ? 'default' : 'small';
|
||||
return (
|
||||
<Group onChange={this.onInternalTypeChange} value={type} size={size}>
|
||||
|
@ -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(() => <Header value={Moment()} />);
|
||||
|
||||
it('Calendar should be selectable', () => {
|
||||
const onSelect = jest.fn();
|
||||
const wrapper = mount(<Calendar onSelect={onSelect} />);
|
||||
|
@ -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();
|
||||
});
|
||||
|
@ -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();
|
||||
});
|
||||
|
@ -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(<Cascader options={options} />);
|
||||
|
@ -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();
|
||||
|
@ -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(
|
||||
|
@ -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(
|
||||
<Collapse expandIcon={() => null}>
|
||||
|
6
components/comment/__tests__/index.test.js
Normal file
6
components/comment/__tests__/index.test.js
Normal file
@ -0,0 +1,6 @@
|
||||
import Comment from '../index';
|
||||
import mountTest from '../../../tests/shared/mountTest';
|
||||
|
||||
describe('Comment', () => {
|
||||
mountTest(Comment);
|
||||
});
|
@ -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(() => <ConfigProvider><div /></ConfigProvider>);
|
||||
|
||||
it('Content Security Policy', () => {
|
||||
const csp = { nonce: 'test-antd' };
|
||||
const wrapper = mount(
|
||||
|
11
components/date-picker/__tests__/mount.test.js
Normal file
11
components/date-picker/__tests__/mount.test.js
Normal file
@ -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);
|
||||
});
|
@ -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(() => {
|
||||
|
6
components/divider/__tests__/index.test.js
Normal file
6
components/divider/__tests__/index.test.js
Normal file
@ -0,0 +1,6 @@
|
||||
import Divider from '..';
|
||||
import mountTest from '../../../tests/shared/mountTest';
|
||||
|
||||
describe('Divider', () => {
|
||||
mountTest(Divider);
|
||||
});
|
@ -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(
|
||||
<Drawer visible width={400} getContainer={false}>
|
||||
|
@ -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(() => <Dropdown menu={<Menu />}><span /></Dropdown>);
|
||||
mountTest(Dropdown.Button);
|
||||
|
||||
it('pass appropriate props to Dropdown', () => {
|
||||
const props = {
|
||||
align: {
|
||||
|
@ -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(<Empty imageStyle={{ height: 20 }} />);
|
||||
expect(wrapper.find('.ant-empty-image').props().style.height).toBe(20);
|
||||
|
@ -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(<Form hideRequiredMark />);
|
||||
expect(wrapper.find('form').hasClass('ant-form-hide-required-mark')).toBe(true);
|
||||
|
@ -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(<Col span={2} />);
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
|
@ -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 <i class="xxx"><svg>...</svg></i>', () => {
|
||||
const wrapper = render(<Icon type="message" className="my-icon-classname" />);
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
|
@ -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', () => {
|
||||
|
@ -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(<Input.Password />);
|
||||
@ -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(<Input.Password />);
|
||||
expect(() => {
|
||||
wrapper.unmount();
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
@ -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(<Search enterButton={<button type="button">ok</button>} />);
|
||||
|
@ -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(<Input maxLength={3} />);
|
||||
|
@ -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(
|
||||
<Layout>
|
||||
|
@ -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 => <ListItem>{item}</ListItem>;
|
||||
const renderItem = item => <List.Item>{item}</List.Item>;
|
||||
const dataSource = [];
|
||||
|
||||
const wrapper = mount(<List renderItem={renderItem} dataSource={dataSource} locale={locale} />);
|
||||
|
@ -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(() => <LocaleProvider><div /></LocaleProvider>);
|
||||
|
||||
beforeAll(() => {
|
||||
MockDate.set(moment('2017-09-18T03:30:07.795'));
|
||||
});
|
||||
|
@ -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();
|
||||
});
|
||||
|
@ -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(<Mentions loading />);
|
||||
|
@ -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(() => <Menu><Menu.Item /><Menu.ItemGroup /><Menu.SubMenu /></Menu>);
|
||||
|
||||
beforeEach(() => {
|
||||
jest.useFakeTimers();
|
||||
});
|
||||
|
@ -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(<ModalTester />);
|
||||
expect(wrapper.render()).toMatchSnapshot();
|
||||
|
@ -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 = [
|
||||
{
|
||||
|
6
components/pagination/__tests__/index.test.js
Normal file
6
components/pagination/__tests__/index.test.js
Normal file
@ -0,0 +1,6 @@
|
||||
import Pagination from '..';
|
||||
import mountTest from '../../../tests/shared/mountTest';
|
||||
|
||||
describe('Pagination', () => {
|
||||
mountTest(Pagination);
|
||||
});
|
@ -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),
|
||||
|
@ -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(
|
||||
<Popover content="console.log('hello world')" title="code" trigger="click">
|
||||
|
@ -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(<Progress percent={100} successPercent={50} />);
|
||||
expect(wrapper.find('.ant-progress-status-success')).toHaveLength(0);
|
||||
|
@ -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`] = `
|
||||
<div
|
||||
class="my-radio-group my-radio-group-outline"
|
||||
>
|
||||
|
@ -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 (
|
||||
<RadioGroup {...props}>
|
||||
|
@ -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(<Radio className="customized">Test</Radio>);
|
||||
|
@ -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);
|
||||
});
|
||||
|
@ -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(
|
||||
<Result
|
||||
|
@ -3,11 +3,13 @@ import { mount } from 'enzyme';
|
||||
import Select from '..';
|
||||
import Icon from '../../icon';
|
||||
import focusTest from '../../../tests/shared/focusTest';
|
||||
import mountTest from '../../../tests/shared/mountTest';
|
||||
|
||||
const { Option } = Select;
|
||||
|
||||
describe('Select', () => {
|
||||
focusTest(Select);
|
||||
mountTest(Select);
|
||||
|
||||
beforeEach(() => {
|
||||
jest.useFakeTimers();
|
||||
|
@ -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', () => {
|
||||
</Skeleton>,
|
||||
);
|
||||
|
||||
mountTest(Skeleton);
|
||||
|
||||
describe('avatar', () => {
|
||||
it('size', () => {
|
||||
const wrapperSmall = genSkeleton({ avatar: { size: 'small' } });
|
||||
|
@ -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(<Slider defaultValue={30} />);
|
||||
wrapper
|
||||
|
@ -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 <Spin>xx</Spin>', () => {
|
||||
const wrapper = mount(
|
||||
<Spin style={{ background: 'red' }}>
|
||||
|
@ -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'));
|
||||
});
|
||||
|
6
components/steps/__tests__/index.test.js
Normal file
6
components/steps/__tests__/index.test.js
Normal file
@ -0,0 +1,6 @@
|
||||
import Steps from '..';
|
||||
import mountTest from '../../../tests/shared/mountTest';
|
||||
|
||||
describe('Steps', () => {
|
||||
mountTest(Steps);
|
||||
});
|
@ -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(<Switch />);
|
||||
|
@ -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(() => {
|
||||
|
@ -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(() => <Tabs><TabPane tab="xx" key="xx" /></Tabs>);
|
||||
|
||||
describe('editable-card', () => {
|
||||
let handleEdit;
|
||||
let wrapper;
|
||||
|
@ -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();
|
||||
});
|
||||
|
@ -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 = () => <button type="button">Ok</button>;
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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(<Transfer {...listCommonProps} />);
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
|
@ -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', () => {
|
||||
|
@ -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(() => {
|
||||
|
@ -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(() => {});
|
||||
|
||||
|
@ -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());
|
||||
|
||||
|
15
tests/shared/mountTest.js
Normal file
15
tests/shared/mountTest.js
Normal file
@ -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(<Component />);
|
||||
expect(() => {
|
||||
wrapper.setProps({});
|
||||
wrapper.unmount();
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user