Browse Source

test: Add eslint-plugin-jest (#15825)

pull/15829/head
偏右 6 years ago
committed by zombieJ
parent
commit
ad99b4322d
  1. 13
      .eslintrc.js
  2. 2
      components/__tests__/index.test.js
  3. 6
      components/_util/__tests__/util.test.js
  4. 4
      components/alert/__tests__/index.test.js
  5. 27
      components/auto-complete/__tests__/focus.test.js
  6. 2
      components/avatar/__tests__/Avatar.test.js
  7. 8
      components/calendar/__tests__/index.test.js
  8. 6
      components/card/__tests__/index.test.js
  9. 8
      components/carousel/__tests__/index.test.js
  10. 2
      components/cascader/__tests__/index.test.js
  11. 27
      components/checkbox/__tests__/group.test.js
  12. 2
      components/config-provider/__tests__/components.test.js
  13. 6
      components/date-picker/__tests__/DatePicker.test.js
  14. 4
      components/date-picker/__tests__/RangePicker.test.js
  15. 2
      components/drawer/__tests__/MultiDrawer.test.js
  16. 2
      components/form/__tests__/message.test.js
  17. 2
      components/grid/__tests__/index.test.js
  18. 8
      components/icon/__tests__/index.test.js
  19. 12
      components/input/__tests__/Search.test.js
  20. 8
      components/input/__tests__/index.test.js
  21. 6
      components/layout/__tests__/index.test.js
  22. 2
      components/list/__tests__/pagination.test.js
  23. 10
      components/mention/__tests__/index.test.js
  24. 3
      components/message/__tests__/index.test.js
  25. 4
      components/modal/__tests__/Modal.test.js
  26. 2
      components/modal/__tests__/confirm.test.js
  27. 2
      components/page-header/__tests__/index.test.js
  28. 8
      components/radio/__tests__/group.test.js
  29. 8
      components/statistic/__tests__/index.test.js
  30. 6
      components/table/__tests__/Table.filter.test.js
  31. 4
      components/table/__tests__/Table.pagination.test.js
  32. 30
      components/table/__tests__/Table.rowSelection.test.js
  33. 2
      components/table/__tests__/Table.test.js
  34. 2
      components/tabs/__tests__/index.test.js
  35. 2
      components/tag/__tests__/index.test.js
  36. 2
      components/time-picker/__tests__/index.test.js
  37. 16
      components/tooltip/__tests__/tooltip.test.js
  38. 2
      components/transfer/__tests__/index.test.js
  39. 2
      components/transfer/__tests__/list.test.js
  40. 4
      components/transfer/__tests__/search.test.js
  41. 12
      components/typography/__tests__/index.test.js
  42. 10
      components/upload/__tests__/upload.test.js
  43. 18
      components/upload/__tests__/uploadlist.test.js
  44. 1
      package.json
  45. 6
      tests/shared/focusTest.js

13
.eslintrc.js

@ -1,5 +1,9 @@
const eslintrc = {
extends: ['airbnb', 'prettier'],
extends: [
'airbnb',
'prettier',
'plugin:jest/recommended',
],
env: {
browser: true,
node: true,
@ -8,7 +12,12 @@ const eslintrc = {
es6: true,
},
parser: 'babel-eslint',
plugins: ['markdown', 'react', 'babel'],
plugins: [
'markdown',
'react',
'babel',
'jest',
],
rules: {
'react/jsx-one-expression-per-line': 0,
'react/prop-types': 0,

2
components/__tests__/index.test.js

@ -13,7 +13,7 @@ describe('antd', () => {
});
it('should hint when import all components in dev mode', () => {
expect(warnSpy).toBeCalledWith(
expect(warnSpy).toHaveBeenCalledWith(
'You are using a whole package of antd, please use https://www.npmjs.com/package/babel-plugin-import to reduce app bundle size.',
);
warnSpy.mockRestore();

6
components/_util/__tests__/util.test.js

@ -19,13 +19,13 @@ describe('Test utils function', () => {
it('throttle function should work', () => {
const callback = jest.fn();
const throttled = throttleByAnimationFrame(callback);
expect(callback).not.toBeCalled();
expect(callback).not.toHaveBeenCalled();
throttled();
throttled();
jest.runAllTimers();
expect(callback).toBeCalled();
expect(callback).toHaveBeenCalled();
expect(callback.mock.calls.length).toBe(1);
});
@ -37,7 +37,7 @@ describe('Test utils function', () => {
throttled.cancel();
jest.runAllTimers();
expect(callback).not.toBeCalled();
expect(callback).not.toHaveBeenCalled();
});
describe('getDataOrAriaProps', () => {

4
components/alert/__tests__/index.test.js

@ -24,9 +24,9 @@ describe('Alert', () => {
/>,
);
wrapper.find('.ant-alert-close-icon').simulate('click');
expect(onClose).toBeCalled();
expect(onClose).toHaveBeenCalled();
jest.runAllTimers();
expect(afterClose).toBeCalled();
expect(afterClose).toHaveBeenCalled();
});
describe('data and aria props', () => {

27
components/auto-complete/__tests__/focus.test.js

@ -28,23 +28,28 @@ describe('AutoComplete children could be focus', () => {
it('focus() and onFocus', () => {
const handleFocus = jest.fn();
const wrapper = mount(
<AutoComplete onFocus={handleFocus} />
, { attachTo: container });
wrapper.find('input').instance().focus();
const wrapper = mount(<AutoComplete onFocus={handleFocus} />, { attachTo: container });
wrapper
.find('input')
.instance()
.focus();
jest.runAllTimers();
expect(handleFocus).toBeCalled();
expect(handleFocus).toHaveBeenCalled();
});
it('blur() and onBlur', () => {
const handleBlur = jest.fn();
const wrapper = mount(
<AutoComplete onBlur={handleBlur} />
, { attachTo: container });
wrapper.find('input').instance().focus();
const wrapper = mount(<AutoComplete onBlur={handleBlur} />, { attachTo: container });
wrapper
.find('input')
.instance()
.focus();
jest.runAllTimers();
wrapper.find('input').instance().blur();
wrapper
.find('input')
.instance()
.blur();
jest.runAllTimers();
expect(handleBlur).toBeCalled();
expect(handleBlur).toHaveBeenCalled();
});
});

2
components/avatar/__tests__/Avatar.test.js

@ -46,7 +46,7 @@ describe('Avatar Render', () => {
const children = wrapper.find('.ant-avatar-string');
expect(children.length).toBe(1);
expect(children.text()).toBe('Fallback');
expect(wrapper.instance().setScale).toBeCalled();
expect(wrapper.instance().setScale).toHaveBeenCalled();
expect(div.querySelector('.ant-avatar-string').style.transform).toContain('scale(0.5)');
wrapper.detach();

8
components/calendar/__tests__/index.test.js

@ -13,7 +13,7 @@ describe('Calendar', () => {
.find('.ant-fullcalendar-cell')
.at(0)
.simulate('click');
expect(onSelect).toBeCalledWith(expect.anything());
expect(onSelect).toHaveBeenCalledWith(expect.anything());
const value = onSelect.mock.calls[0][0];
expect(Moment.isMoment(value)).toBe(true);
});
@ -159,7 +159,7 @@ describe('Calendar', () => {
.at(0)
.simulate('click');
expect(onPanelChange).toBeCalled();
expect(onPanelChange).toHaveBeenCalled();
expect(onPanelChange.mock.calls[0][0].month()).toEqual(date.month() - 1);
});
@ -173,7 +173,7 @@ describe('Calendar', () => {
wrapper.find('.ant-radio-button-input[value="year"]').simulate('change');
expect(wrapper.find('.ant-fullcalendar-table').length).toBe(0);
expect(wrapper.find('.ant-fullcalendar-month-panel-table').length).toBe(1);
expect(onPanelChange).toBeCalled();
expect(onPanelChange).toHaveBeenCalled();
expect(onPanelChange.mock.calls[0][1]).toEqual('year');
});
@ -254,6 +254,6 @@ describe('Calendar', () => {
.find('input')
.at(1)
.simulate('change');
expect(onTypeChange).toBeCalledWith('year');
expect(onTypeChange).toHaveBeenCalledWith('year');
});
});

6
components/card/__tests__/index.test.js

@ -33,11 +33,11 @@ describe('Card', () => {
it('warning', () => {
const warnSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
mount(<Card noHovering>xxx</Card>);
expect(warnSpy).toBeCalledWith(
expect(warnSpy).toHaveBeenCalledWith(
'Warning: [antd: Card] `noHovering` is deprecated, you can remove it safely or use `hoverable` instead.',
);
mount(<Card noHovering={false}>xxx</Card>);
expect(warnSpy).toBeCalledWith(
expect(warnSpy).toHaveBeenCalledWith(
'Warning: [antd: Card] `noHovering={false}` is deprecated, use `hoverable` instead.',
);
warnSpy.mockRestore();
@ -64,7 +64,7 @@ describe('Card', () => {
.find('.ant-tabs-tab')
.at(1)
.simulate('click');
expect(onTabChange).toBeCalledWith('tab2');
expect(onTabChange).toHaveBeenCalledWith('tab2');
});
it('getCompatibleHoverable should work', () => {

8
components/carousel/__tests__/index.test.js

@ -58,9 +58,9 @@ describe('Carousel', () => {
);
const spy = jest.spyOn(wrapper.instance().slick.innerSlider, 'autoPlay');
window.resizeTo(1000);
expect(spy).not.toBeCalled();
expect(spy).not.toHaveBeenCalled();
await new Promise(resolve => setTimeout(resolve, 500));
expect(spy).toBeCalled();
expect(spy).toHaveBeenCalled();
});
it('cancel resize listener when unmount', async () => {
@ -75,7 +75,7 @@ describe('Carousel', () => {
const spy = jest.spyOn(wrapper.instance().onWindowResized, 'cancel');
const spy2 = jest.spyOn(window, 'removeEventListener');
wrapper.unmount();
expect(spy).toBeCalled();
expect(spy2).toBeCalledWith('resize', onWindowResized);
expect(spy).toHaveBeenCalled();
expect(spy2).toHaveBeenCalledWith('resize', onWindowResized);
});
});

2
components/cascader/__tests__/index.test.js

@ -424,7 +424,7 @@ describe('Cascader', () => {
wrapper.find('input').simulate('click');
wrapper.find('input').simulate('change', { target: { value: 'a' } });
expect(wrapper.find('.ant-cascader-menu-item').length).toBe(2);
expect(errorSpy).toBeCalledWith(
expect(errorSpy).toHaveBeenCalledWith(
"Warning: [antd: Cascader] 'limit' of showSearch should be positive number or false.",
);
});

27
components/checkbox/__tests__/group.test.js

@ -12,22 +12,22 @@ describe('CheckboxGroup', () => {
.find('.ant-checkbox-input')
.at(0)
.simulate('change');
expect(onChange).toBeCalledWith(['Apple']);
expect(onChange).toHaveBeenCalledWith(['Apple']);
wrapper
.find('.ant-checkbox-input')
.at(1)
.simulate('change');
expect(onChange).toBeCalledWith(['Apple', 'Pear']);
expect(onChange).toHaveBeenCalledWith(['Apple', 'Pear']);
wrapper
.find('.ant-checkbox-input')
.at(2)
.simulate('change');
expect(onChange).toBeCalledWith(['Apple', 'Pear', 'Orange']);
expect(onChange).toHaveBeenCalledWith(['Apple', 'Pear', 'Orange']);
wrapper
.find('.ant-checkbox-input')
.at(1)
.simulate('change');
expect(onChange).toBeCalledWith(['Apple', 'Orange']);
expect(onChange).toHaveBeenCalledWith(['Apple', 'Orange']);
});
it('does not trigger onChange callback of both Checkbox and CheckboxGroup when CheckboxGroup is disabled', () => {
@ -42,12 +42,12 @@ describe('CheckboxGroup', () => {
.find('.ant-checkbox-input')
.at(0)
.simulate('change');
expect(onChangeGroup).not.toBeCalled();
expect(onChangeGroup).not.toHaveBeenCalled();
groupWrapper
.find('.ant-checkbox-input')
.at(1)
.simulate('change');
expect(onChangeGroup).not.toBeCalled();
expect(onChangeGroup).not.toHaveBeenCalled();
});
it('does not prevent onChange callback from Checkbox when CheckboxGroup is not disabled', () => {
@ -63,22 +63,19 @@ describe('CheckboxGroup', () => {
.find('.ant-checkbox-input')
.at(0)
.simulate('change');
expect(onChangeGroup).toBeCalledWith(['Apple']);
expect(onChangeGroup).toHaveBeenCalledWith(['Apple']);
groupWrapper
.find('.ant-checkbox-input')
.at(1)
.simulate('change');
expect(onChangeGroup).toBeCalledWith(['Apple']);
expect(onChangeGroup).toHaveBeenCalledWith(['Apple']);
});
it('all children should have a name property', () => {
const wrapper = mount(<Checkbox.Group name="checkboxgroup" options={['Yes', 'No']} />);
expect(
wrapper.find('input[type="checkbox"]').forEach(el => {
expect(el.props().name).toEqual('checkboxgroup');
}),
);
wrapper.find('input[type="checkbox"]').forEach(el => {
expect(el.props().name).toEqual('checkboxgroup');
});
});
it('passes prefixCls down to checkbox', () => {
@ -111,7 +108,7 @@ describe('CheckboxGroup', () => {
.find('.ant-checkbox-input')
.at(0)
.simulate('change');
expect(onChange).toBeCalled();
expect(onChange).toHaveBeenCalled();
expect(onChange.mock.calls[0][0].target.value).toEqual('my');
});
});

2
components/config-provider/__tests__/components.test.js

@ -60,7 +60,7 @@ jest.mock('rc-util/lib/Portal');
describe('ConfigProvider', () => {
describe('components', () => {
function testPair(name, renderComponent) {
describe(name, () => {
describe(`${name}`, () => {
// normal
it('normal', () => {
expect(render(renderComponent({}))).toMatchSnapshot();

6
components/date-picker/__tests__/DatePicker.test.js

@ -114,11 +114,11 @@ describe('DatePicker', () => {
const wrapper = mount(<DatePicker onChange={handleChange} />);
openPanel(wrapper);
nextYear(wrapper);
expect(handleChange).not.toBeCalled();
expect(handleChange).not.toHaveBeenCalled();
nextMonth(wrapper);
expect(handleChange).not.toBeCalled();
expect(handleChange).not.toHaveBeenCalled();
selectDate(wrapper, moment('2017-12-22'));
expect(handleChange).toBeCalled();
expect(handleChange).toHaveBeenCalled();
});
it('clear input', () => {

4
components/date-picker/__tests__/RangePicker.test.js

@ -260,7 +260,7 @@ describe('RangePicker', () => {
const wrapper = mount(<RangePicker ranges={{ 'recent two days': range }} onOk={handleOk} />);
wrapper.find('.ant-calendar-picker-input').simulate('click');
wrapper.find('.ant-calendar-range-quick-selector Tag').simulate('click');
expect(handleOk).toBeCalledWith(range);
expect(handleOk).toHaveBeenCalledWith(range);
});
// https://github.com/ant-design/ant-design/issues/9267
@ -312,7 +312,7 @@ describe('RangePicker', () => {
);
wrapper.find('.ant-calendar-picker-input').simulate('click');
wrapper.find('.ant-calendar-range-quick-selector Tag').simulate('click');
expect(handleOpenChange).toBeCalledWith(false);
expect(handleOpenChange).toHaveBeenCalledWith(false);
});
it('customize separator', () => {

2
components/drawer/__tests__/MultiDrawer.test.js

@ -113,7 +113,7 @@ describe('Drawer', () => {
expect(wrapper.state().childrenDrawer).toBe(false);
});
it('render left MultiDrawer', () => {
it('render top MultiDrawer', () => {
const wrapper = mount(<MultiDrawer placement="top" />);
wrapper.find('button#open_drawer').simulate('click');
wrapper.find('button#open_two_drawer').simulate('click');

2
components/form/__tests__/message.test.js

@ -102,7 +102,7 @@ describe('Form', () => {
});
mount(<Form1 />);
expect(errorSpy).toBeCalledWith(
expect(errorSpy).toHaveBeenCalledWith(
'Warning: [antd: Form.Item] Cannot generate `validateStatus` and `help` automatically, while there are more than one `getFieldDecorator` in it.',
);
errorSpy.mockRestore();

2
components/grid/__tests__/index.test.js

@ -47,7 +47,7 @@ describe('Grid', () => {
.prop('style'),
).toEqual(undefined);
wrapper.unmount();
expect(enquire.unregister).toBeCalledTimes(6);
expect(enquire.unregister).toHaveBeenCalledTimes(6);
});
it('renders wrapped Col correctly', () => {

8
components/icon/__tests__/index.test.js

@ -80,11 +80,11 @@ describe('Icon', () => {
expect(wrapper.find('i')).toHaveLength(1);
const icon = wrapper.find('i').at(0);
icon.simulate('mouseenter');
expect(onVisibleChange).toBeCalledWith(true);
expect(onVisibleChange).toHaveBeenCalledWith(true);
expect(wrapper.instance().tooltip.props.visible).toBe(true);
icon.simulate('mouseleave');
expect(onVisibleChange).toBeCalledWith(false);
expect(onVisibleChange).toHaveBeenCalledWith(false);
expect(wrapper.instance().tooltip.props.visible).toBe(false);
});
@ -115,12 +115,12 @@ describe('Icon', () => {
it('does not warn', () => {
mount(<Icon type="clock-circle-o" theme="outlined" />);
expect(errorSpy).not.toBeCalled();
expect(errorSpy).not.toHaveBeenCalled();
});
it('warns', () => {
mount(<Icon type="clock-circle-o" theme="filled" />);
expect(errorSpy).toBeCalledWith(
expect(errorSpy).toHaveBeenCalledWith(
"Warning: [antd: Icon] The icon name 'clock-circle-o' already specify a theme 'outlined', the 'theme' prop 'filled' will be ignored.",
);
});

12
components/input/__tests__/Search.test.js

@ -34,7 +34,7 @@ describe('Input.Search', () => {
const wrapper = mount(<Search defaultValue="search text" onSearch={onSearch} />);
wrapper.find('.anticon-search').simulate('click');
expect(onSearch).toHaveBeenCalledTimes(1);
expect(onSearch).toBeCalledWith(
expect(onSearch).toHaveBeenCalledWith(
'search text',
expect.objectContaining({
type: 'click',
@ -48,7 +48,7 @@ describe('Input.Search', () => {
const wrapper = mount(<Search defaultValue="search text" enterButton onSearch={onSearch} />);
wrapper.find('Button').simulate('click');
expect(onSearch).toHaveBeenCalledTimes(1);
expect(onSearch).toBeCalledWith(
expect(onSearch).toHaveBeenCalledWith(
'search text',
expect.objectContaining({
type: 'click',
@ -64,7 +64,7 @@ describe('Input.Search', () => {
);
wrapper.find('Button').simulate('click');
expect(onSearch).toHaveBeenCalledTimes(1);
expect(onSearch).toBeCalledWith(
expect(onSearch).toHaveBeenCalledWith(
'search text',
expect.objectContaining({
type: 'click',
@ -84,7 +84,7 @@ describe('Input.Search', () => {
);
wrapper.find('Button').simulate('click');
expect(onSearch).toHaveBeenCalledTimes(1);
expect(onSearch).toBeCalledWith(
expect(onSearch).toHaveBeenCalledWith(
'search text',
expect.objectContaining({
type: 'click',
@ -104,7 +104,7 @@ describe('Input.Search', () => {
);
wrapper.find('button').simulate('click');
expect(onSearch).toHaveBeenCalledTimes(1);
expect(onSearch).toBeCalledWith(
expect(onSearch).toHaveBeenCalledWith(
'search text',
expect.objectContaining({
type: 'click',
@ -118,7 +118,7 @@ describe('Input.Search', () => {
const wrapper = mount(<Search defaultValue="search text" onSearch={onSearch} />);
wrapper.find('input').simulate('keydown', { key: 'Enter', keyCode: 13 });
expect(onSearch).toHaveBeenCalledTimes(1);
expect(onSearch).toBeCalledWith(
expect(onSearch).toHaveBeenCalledWith(
'search text',
expect.objectContaining({
type: 'keydown',

8
components/input/__tests__/index.test.js

@ -41,7 +41,7 @@ describe('Input', () => {
wrapper.setProps({
suffix: 'light',
});
expect(errorSpy).not.toBeCalled();
expect(errorSpy).not.toHaveBeenCalled();
});
it('trigger warning', () => {
const wrapper = mount(<Input />);
@ -52,7 +52,7 @@ describe('Input', () => {
wrapper.setProps({
suffix: 'light',
});
expect(errorSpy).toBeCalledWith(
expect(errorSpy).toHaveBeenCalledWith(
'Warning: [antd: Input] When Input is focused, dynamic add or remove prefix / suffix will make it lose focus caused by dom structure change. Read more: https://ant.design/components/input/#FAQ',
);
});
@ -168,8 +168,8 @@ describe('TextArea', () => {
<TextArea onPressEnter={onPressEnter} onKeyDown={onKeyDown} aria-label="textarea" />,
);
wrapper.instance().handleKeyDown({ keyCode: 13 });
expect(onPressEnter).toBeCalled();
expect(onKeyDown).toBeCalled();
expect(onPressEnter).toHaveBeenCalled();
expect(onKeyDown).toHaveBeenCalled();
});
});

6
components/layout/__tests__/index.test.js

@ -76,12 +76,12 @@ describe('Layout', () => {
it('detect ant-layout-sider-dark as default theme', async () => {
const wrapper = mount(<Sider>Sider</Sider>);
expect(wrapper.find('.ant-layout-sider').hasClass('ant-layout-sider-dark'));
expect(wrapper.find('.ant-layout-sider').hasClass('ant-layout-sider-dark')).toBe(true);
});
it('detect ant-layout-sider-light when set light theme', async () => {
const wrapper = mount(<Sider theme="light">Sider</Sider>);
expect(wrapper.find('.ant-layout-sider').hasClass('ant-layout-sider-light'));
expect(wrapper.find('.ant-layout-sider').hasClass('ant-layout-sider-light')).toBe(true);
});
it('renders string width correctly', () => {
@ -125,6 +125,6 @@ describe('Sider onBreakpoint', () => {
Sider
</Sider>,
);
expect(onBreakpoint).toBeCalledWith(true);
expect(onBreakpoint).toHaveBeenCalledWith(true);
});
});

2
components/list/__tests__/pagination.test.js

@ -84,7 +84,7 @@ describe('List.pagination', () => {
.last()
.simulate('click');
expect(handlePaginationChange).toBeCalledWith(2, 2);
expect(handlePaginationChange).toHaveBeenCalledWith(2, 2);
});
// https://github.com/ant-design/ant-design/issues/4532

10
components/mention/__tests__/index.test.js

@ -24,7 +24,7 @@ describe('Mention', () => {
);
wrapper.instance().focus();
jest.runAllTimers();
expect(handleFocus).toBeCalled();
expect(handleFocus).toHaveBeenCalled();
});
it('basic suggestion', () => {
@ -36,7 +36,7 @@ describe('Mention', () => {
const ed = wrapper.find('.public-DraftEditor-content');
ed.simulate('beforeInput', { data: '@a' });
jest.runAllTimers();
expect(handleSearch).toBeCalledWith('a', '@');
expect(handleSearch).toHaveBeenCalledWith('a', '@');
});
it('change suggestions', () => {
@ -73,8 +73,8 @@ describe('Mention', () => {
const ed = wrapper.find('.public-DraftEditor-content');
ed.simulate('beforeInput', { data: '@' });
jest.runAllTimers();
expect(onChange).toBeCalled();
expect(onSelect).not.toBeCalled();
expect(onChange).toHaveBeenCalled();
expect(onSelect).not.toHaveBeenCalled();
// enzyme cannot find .ant-mention-dropdown-item in react 15
// I don't know why
if (process.env.REACT === '15') {
@ -93,7 +93,7 @@ describe('Mention', () => {
.at(0)
.simulate('click');
jest.runAllTimers();
expect(onSelect).toBeCalled();
expect(onSelect).toHaveBeenCalled();
expect(wrapper.find('.public-DraftStyleDefault-block').text()).toBe('@afc163 ');
});

3
components/message/__tests__/index.test.js

@ -86,7 +86,7 @@ describe('message', () => {
});
});
it('should be called like promise', () => {
it('should be called like promise', done => {
jest.useRealTimers();
const defaultDuration = 3;
const now = Date.now();
@ -94,6 +94,7 @@ describe('message', () => {
// calculate the approximately duration value
const aboutDuration = parseInt((Date.now() - now) / 1000, 10);
expect(aboutDuration).toBe(defaultDuration);
done();
});
});

4
components/modal/__tests__/Modal.test.js

@ -48,13 +48,13 @@ describe('Modal', () => {
const onCancel = jest.fn();
const wrapper = mount(<Modal onCancel={onCancel} />).instance();
wrapper.handleCancel();
expect(onCancel).toBeCalled();
expect(onCancel).toHaveBeenCalled();
});
it('onOk should be called', () => {
const onOk = jest.fn();
const wrapper = mount(<Modal onOk={onOk} />).instance();
wrapper.handleOk();
expect(onOk).toBeCalled();
expect(onOk).toHaveBeenCalled();
});
});

2
components/modal/__tests__/confirm.test.js

@ -92,7 +92,7 @@ describe('Modal.confirm triggers callbacks correctly', () => {
expect($$('.ant-btn')[1].disabled).toBe(true);
});
it('trigger onCancel once when click on cancel button', () => {
it('should close modals when click confirm button', () => {
jest.useFakeTimers();
['info', 'success', 'warning', 'error'].forEach(type => {
Modal[type]({

2
components/page-header/__tests__/index.test.js

@ -36,7 +36,7 @@ describe('PageHeader', () => {
const callback = jest.fn(() => true);
const wrapper = mount(<PageHeader title="Page Title" onBack={callback} />);
wrapper.find('.ant-page-header-back-icon').simulate('click');
expect(callback).toBeCalled();
expect(callback).toHaveBeenCalled();
});
it('pageHeader should support className', () => {

8
components/radio/__tests__/group.test.js

@ -164,11 +164,9 @@ describe('Radio', () => {
const GROUP_NAME = 'radiogroup';
const wrapper = mount(createRadioGroup({ name: GROUP_NAME }));
expect(
wrapper.find('input[type="radio"]').forEach(el => {
expect(el.props().name).toEqual(GROUP_NAME);
}),
);
wrapper.find('input[type="radio"]').forEach(el => {
expect(el.props().name).toEqual(GROUP_NAME);
});
});
it('passes prefixCls down to radio', () => {

8
components/statistic/__tests__/index.test.js

@ -18,7 +18,7 @@ describe('Statistic', () => {
it('customize formatter', () => {
const formatter = jest.fn(() => 93);
const wrapper = mount(<Statistic value={1128} formatter={formatter} />);
expect(formatter).toBeCalledWith(1128);
expect(formatter).toHaveBeenCalledWith(1128);
expect(wrapper.find('.ant-statistic-content-value').text()).toEqual('93');
});
@ -73,7 +73,7 @@ describe('Statistic', () => {
wrapper.unmount();
expect(instance.countdownId).toBe(undefined);
expect(onFinish).not.toBeCalled();
expect(onFinish).not.toHaveBeenCalled();
});
describe('time finished', () => {
@ -86,7 +86,7 @@ describe('Statistic', () => {
const instance = wrapper.instance();
expect(instance.countdownId).toBe(undefined);
expect(onFinish).not.toBeCalled();
expect(onFinish).not.toHaveBeenCalled();
});
it('called if finished', async () => {
@ -99,7 +99,7 @@ describe('Statistic', () => {
MockDate.set(moment('2019-11-28 00:00:00'));
jest.runAllTimers();
expect(onFinish).toBeCalled();
expect(onFinish).toHaveBeenCalled();
jest.useFakeTimers();
});
});

6
components/table/__tests__/Table.filter.test.js

@ -223,7 +223,7 @@ describe('Table.filter', () => {
.first()
.simulate('click');
expect(handleChange).toBeCalledWith(true);
expect(handleChange).toHaveBeenCalledWith(true);
});
it('can be controlled by filteredValue', () => {
@ -285,7 +285,7 @@ describe('Table.filter', () => {
.simulate('click');
dropdownWrapper.find('.confirm').simulate('click');
expect(handleChange).toBeCalledWith(
expect(handleChange).toHaveBeenCalledWith(
{},
{ name: ['boy'] },
{},
@ -523,7 +523,7 @@ describe('Table.filter', () => {
.first()
.simulate('click');
expect(handleChange).toBeCalled();
expect(handleChange).toHaveBeenCalled();
expect(handleChange.mock.calls[0][3].currentDataSource.length).toBe(1);
});

4
components/table/__tests__/Table.pagination.test.js

@ -86,7 +86,7 @@ describe('Table.pagination', () => {
.last()
.simulate('click');
expect(handleChange).toBeCalledWith(
expect(handleChange).toHaveBeenCalledWith(
{
className: 'my-page',
current: 2,
@ -104,7 +104,7 @@ describe('Table.pagination', () => {
},
);
expect(handlePaginationChange).toBeCalledWith(2, 2);
expect(handlePaginationChange).toHaveBeenCalledWith(2, 2);
});
// https://github.com/ant-design/ant-design/issues/4532

30
components/table/__tests__/Table.rowSelection.test.js

@ -131,7 +131,7 @@ describe('Table.rowSelection', () => {
expect(checkboxs.at(1).props().checked).toBe(true);
expect(checkboxs.at(2).props().checked).toBe(true);
expect(errorSpy).toBeCalledWith(
expect(errorSpy).toHaveBeenCalledWith(
'Warning: [antd: Table] Do not set `checked` or `defaultChecked` in `getCheckboxProps`. Please use `selectedRowKeys` instead.',
);
});
@ -166,7 +166,7 @@ describe('Table.rowSelection', () => {
.last()
.simulate('change', { target: { checked: true } });
expect(handleChange).toBeCalledWith([3], [{ key: 3, name: 'Jerry' }]);
expect(handleChange).toHaveBeenCalledWith([3], [{ key: 3, name: 'Jerry' }]);
expect(handleSelect.mock.calls.length).toBe(1);
expect(handleSelect.mock.calls[0][0]).toEqual({ key: 3, name: 'Jerry' });
expect(handleSelect.mock.calls[0][1]).toEqual(true);
@ -190,7 +190,7 @@ describe('Table.rowSelection', () => {
target: { checked: true },
nativeEvent: { shiftKey: true },
});
expect(handleSelect).toBeCalled();
expect(handleSelect).toHaveBeenCalled();
wrapper
.find('input')
@ -199,7 +199,11 @@ describe('Table.rowSelection', () => {
target: { checked: true },
nativeEvent: { shiftKey: true },
});
expect(handleSelectMulti).toBeCalledWith(true, [data[0], data[1], data[2]], [data[1], data[2]]);
expect(handleSelectMulti).toHaveBeenCalledWith(
true,
[data[0], data[1], data[2]],
[data[1], data[2]],
);
wrapper
.find('input')
@ -208,7 +212,7 @@ describe('Table.rowSelection', () => {
target: { checked: false },
nativeEvent: { shiftKey: true },
});
expect(handleSelectMulti).toBeCalledWith(false, [], [data[0], data[1], data[2]]);
expect(handleSelectMulti).toHaveBeenCalledWith(false, [], [data[0], data[1], data[2]]);
});
it('fires selectAll event', () => {
@ -222,13 +226,13 @@ describe('Table.rowSelection', () => {
.find('input')
.first()
.simulate('change', { target: { checked: true } });
expect(handleSelectAll).toBeCalledWith(true, data, data);
expect(handleSelectAll).toHaveBeenCalledWith(true, data, data);
wrapper
.find('input')
.first()
.simulate('change', { target: { checked: false } });
expect(handleSelectAll).toBeCalledWith(false, [], data);
expect(handleSelectAll).toHaveBeenCalledWith(false, [], data);
});
it('render with default selection correctly', () => {
@ -264,7 +268,7 @@ describe('Table.rowSelection', () => {
.first()
.simulate('click');
expect(handleSelectAll).toBeCalledWith(true, data, data);
expect(handleSelectAll).toHaveBeenCalledWith(true, data, data);
});
it('fires selectInvert event', () => {
@ -288,7 +292,7 @@ describe('Table.rowSelection', () => {
.last()
.simulate('click');
expect(handleSelectInvert).toBeCalledWith([1, 2, 3]);
expect(handleSelectInvert).toHaveBeenCalledWith([1, 2, 3]);
});
it('fires selection event', () => {
@ -322,13 +326,13 @@ describe('Table.rowSelection', () => {
.find('.ant-dropdown-menu-item > div')
.at(2)
.simulate('click');
expect(handleSelectOdd).toBeCalledWith([0, 1, 2, 3]);
expect(handleSelectOdd).toHaveBeenCalledWith([0, 1, 2, 3]);
dropdownWrapper
.find('.ant-dropdown-menu-item > div')
.at(3)
.simulate('click');
expect(handleSelectEven).toBeCalledWith([0, 1, 2, 3]);
expect(handleSelectEven).toHaveBeenCalledWith([0, 1, 2, 3]);
});
it('could hide default selection options', () => {
@ -387,13 +391,13 @@ describe('Table.rowSelection', () => {
.find('.ant-dropdown-menu-item > div')
.at(0)
.simulate('click');
expect(handleSelectOdd).toBeCalledWith([0, 1, 2, 3]);
expect(handleSelectOdd).toHaveBeenCalledWith([0, 1, 2, 3]);
dropdownWrapper
.find('.ant-dropdown-menu-item > div')
.at(1)
.simulate('click');
expect(handleSelectEven).toBeCalledWith([0, 1, 2, 3]);
expect(handleSelectEven).toHaveBeenCalledWith([0, 1, 2, 3]);
});
// https://github.com/ant-design/ant-design/issues/4245

2
components/table/__tests__/Table.test.js

@ -89,7 +89,7 @@ describe('Table', () => {
it('warning if both `expandedRowRender` & `scroll` are used', () => {
mount(<Table expandedRowRender={() => null} scroll={{}} />);
expect(warnSpy).toBeCalledWith(
expect(warnSpy).toHaveBeenCalledWith(
'Warning: [antd: Table] `expandedRowRender` and `scroll` are not compatible. Please use one of them at one time.',
);
});

2
components/tabs/__tests__/index.test.js

@ -30,7 +30,7 @@ describe('Tabs', () => {
it('remove card', () => {
wrapper.find('.anticon-close').simulate('click');
expect(handleEdit).toBeCalledWith('1', 'remove');
expect(handleEdit).toHaveBeenCalledWith('1', 'remove');
});
});

2
components/tag/__tests__/index.test.js

@ -17,7 +17,7 @@ describe('Tag', () => {
expect(wrapper.find('.anticon-close').length).toBe(1);
expect(wrapper.find('div.ant-tag:not(.ant-tag-hidden)').length).toBe(1);
wrapper.find('.anticon-close').simulate('click');
expect(onClose).toBeCalled();
expect(onClose).toHaveBeenCalled();
jest.runAllTimers();
wrapper.update();
expect(wrapper.find('div.ant-tag:not(.ant-tag-hidden)').length).toBe(0);

2
components/time-picker/__tests__/index.test.js

@ -29,7 +29,7 @@ describe('TimePicker', () => {
it('allowEmpty deprecated', () => {
mount(<TimePicker allowEmpty />);
expect(errorSpy).toBeCalledWith(
expect(errorSpy).toHaveBeenCalledWith(
'Warning: [antd: TimePicker] `allowEmpty` is deprecated. Please use `allowClear` instead.',
);
});

16
components/tooltip/__tests__/tooltip.test.js

@ -69,11 +69,11 @@ describe('Tooltip', () => {
expect(wrapper.find('span')).toHaveLength(1);
const button = wrapper.find('span').at(0);
button.simulate('mouseenter');
expect(onVisibleChange).toBeCalledWith(true);
expect(onVisibleChange).toHaveBeenCalledWith(true);
expect(wrapper.instance().tooltip.props.visible).toBe(true);
button.simulate('mouseleave');
expect(onVisibleChange).toBeCalledWith(false);
expect(onVisibleChange).toHaveBeenCalledWith(false);
expect(wrapper.instance().tooltip.props.visible).toBe(false);
});
@ -93,11 +93,11 @@ describe('Tooltip', () => {
expect(wrapper.render()).toMatchSnapshot();
const button = wrapper.find('span').at(0);
button.simulate('mouseenter');
expect(onVisibleChange).toBeCalledWith(true);
expect(onVisibleChange).toHaveBeenCalledWith(true);
expect(wrapper.instance().tooltip.props.visible).toBe(true);
button.simulate('mouseleave');
expect(onVisibleChange).toBeCalledWith(false);
expect(onVisibleChange).toHaveBeenCalledWith(false);
expect(wrapper.instance().tooltip.props.visible).toBe(false);
});
@ -196,12 +196,12 @@ describe('Tooltip', () => {
const picker = wrapper.find('span.ant-calendar-picker').at(0);
picker.simulate('mouseenter');
await delay(100);
expect(onVisibleChange).toBeCalledWith(true);
expect(onVisibleChange).toHaveBeenCalledWith(true);
expect(wrapper.instance().tooltip.props.visible).toBe(true);
picker.simulate('mouseleave');
await delay(100);
expect(onVisibleChange).toBeCalledWith(false);
expect(onVisibleChange).toHaveBeenCalledWith(false);
expect(wrapper.instance().tooltip.props.visible).toBe(false);
});
@ -221,12 +221,12 @@ describe('Tooltip', () => {
const picker = wrapper.find('Group').at(0);
picker.simulate('mouseenter');
await delay(100);
expect(onVisibleChange).toBeCalledWith(true);
expect(onVisibleChange).toHaveBeenCalledWith(true);
expect(wrapper.instance().tooltip.props.visible).toBe(true);
picker.simulate('mouseleave');
await delay(100);
expect(onVisibleChange).toBeCalledWith(false);
expect(onVisibleChange).toHaveBeenCalledWith(false);
expect(wrapper.instance().tooltip.props.visible).toBe(false);
});
});

2
components/transfer/__tests__/index.test.js

@ -268,7 +268,7 @@ describe('Transfer', () => {
.text(),
).toEqual('old1');
expect(consoleErrorSpy).toBeCalledWith(
expect(consoleErrorSpy).toHaveBeenCalledWith(
'Warning: [antd: Transfer] `notFoundContent` and `searchPlaceholder` will be removed, please use `locale` instead.',
);
consoleErrorSpy.mockRestore();

2
components/transfer/__tests__/list.test.js

@ -52,6 +52,6 @@ describe('List', () => {
const handleFilter = jest.fn();
const wrapper = mount(<List {...listCommonProps} handleFilter={handleFilter} />);
expect(wrapper.instance().handleFilter({ target: 'test' })).toBe(undefined);
expect(handleFilter).toBeCalled();
expect(handleFilter).toHaveBeenCalled();
});
});

4
components/transfer/__tests__/search.test.js

@ -59,7 +59,7 @@ describe('Search', () => {
.find('.ant-input')
.at(0)
.simulate('change', { target: { value: 'a' } });
expect(onSearch).toBeCalledWith('left', 'a');
expect(onSearch).toHaveBeenCalledWith('left', 'a');
onSearch.mockReset();
@ -67,7 +67,7 @@ describe('Search', () => {
.find('.ant-transfer-list-search-action')
.at(0)
.simulate('click');
expect(onSearch).toBeCalledWith('left', '');
expect(onSearch).toHaveBeenCalledWith('left', '');
});
it('legacy onSearchChange', () => {

12
components/typography/__tests__/index.test.js

@ -53,7 +53,7 @@ describe('Typography', () => {
it('warning if `level` not correct', () => {
mount(<Title level={false} />);
expect(errorSpy).toBeCalledWith(
expect(errorSpy).toHaveBeenCalledWith(
'Warning: Title only accept `1 | 2 | 3 | 4` as `level` value.',
);
});
@ -116,7 +116,7 @@ describe('Typography', () => {
wrapper.update();
wrapper.find('.ant-typography-expand').simulate('click');
expect(onExpand).toBeCalled();
expect(onExpand).toHaveBeenCalled();
jest.runAllTimers();
wrapper.update();
@ -146,7 +146,7 @@ describe('Typography', () => {
expect(copy.lastStr).toEqual(target);
wrapper.update();
expect(onCopy).toBeCalled();
expect(onCopy).toHaveBeenCalled();
expect(wrapper.find('.anticon-check').length).toBeTruthy();
@ -175,7 +175,7 @@ describe('Typography', () => {
.first()
.simulate('click');
expect(onStart).toBeCalled();
expect(onStart).toHaveBeenCalled();
wrapper.find('TextArea').simulate('change', {
target: { value: 'Bamboo' },
@ -186,7 +186,7 @@ describe('Typography', () => {
if (expectFunc) {
expectFunc(onChange);
} else {
expect(onChange).toBeCalledWith('Bamboo');
expect(onChange).toHaveBeenCalledWith('Bamboo');
expect(onChange).toHaveBeenCalledTimes(1);
}
});
@ -211,7 +211,7 @@ describe('Typography', () => {
wrapper.find('TextArea').simulate('keyUp', { keyCode: KeyCode.ESC });
},
onChange => {
expect(onChange).not.toBeCalled();
expect(onChange).not.toHaveBeenCalled();
},
);

10
components/upload/__tests__/upload.test.js

@ -37,7 +37,7 @@ describe('Upload', () => {
data,
onChange: ({ file }) => {
if (file.status !== 'uploading') {
expect(data).toBeCalled();
expect(data).toHaveBeenCalled();
done();
}
},
@ -71,7 +71,7 @@ describe('Upload', () => {
data,
onChange: ({ file }) => {
if (file.status !== 'uploading') {
expect(data).toBeCalled();
expect(data).toHaveBeenCalled();
expect(file.name).toEqual('test.png');
done();
}
@ -110,7 +110,7 @@ describe('Upload', () => {
onChange: ({ file, fileList: updatedFileList }) => {
expect(file instanceof File).toBe(true);
expect(updatedFileList.map(f => f.name)).toEqual(['bar.png', 'foo.png']);
expect(data).not.toBeCalled();
expect(data).not.toHaveBeenCalled();
done();
},
};
@ -170,7 +170,7 @@ describe('Upload', () => {
beforeUpload() {},
data,
onChange: () => {
expect(data).toBeCalled();
expect(data).toHaveBeenCalled();
done();
},
};
@ -354,7 +354,7 @@ describe('Upload', () => {
setImmediate(() => {
wrapper.update();
expect(mockRemove).toBeCalled();
expect(mockRemove).toHaveBeenCalled();
expect(props.fileList).toHaveLength(1);
expect(props.fileList[0].status).toBe('done');
done();

18
components/upload/__tests__/uploadlist.test.js

@ -163,12 +163,12 @@ describe('Upload List', () => {
.find('.anticon-eye-o')
.at(0)
.simulate('click');
expect(handlePreview).toBeCalledWith(fileList[0]);
expect(handlePreview).toHaveBeenCalledWith(fileList[0]);
wrapper
.find('.anticon-eye-o')
.at(1)
.simulate('click');
expect(handlePreview).toBeCalledWith(fileList[1]);
expect(handlePreview).toHaveBeenCalledWith(fileList[1]);
});
it('should support onRemove', async () => {
@ -188,12 +188,12 @@ describe('Upload List', () => {
.find('.anticon-delete')
.at(0)
.simulate('click');
expect(handleRemove).toBeCalledWith(fileList[0]);
expect(handleRemove).toHaveBeenCalledWith(fileList[0]);
wrapper
.find('.anticon-delete')
.at(1)
.simulate('click');
expect(handleRemove).toBeCalledWith(fileList[1]);
expect(handleRemove).toHaveBeenCalledWith(fileList[1]);
await delay(0);
expect(handleChange.mock.calls.length).toBe(2);
});
@ -364,7 +364,7 @@ describe('Upload List', () => {
<UploadList listType="picture-card" items={items} locale={{ previewFile: '' }} />,
).instance();
wrapper.previewFile(file, callback);
expect(callback).toBeCalled();
expect(callback).toHaveBeenCalled();
});
it('extname should work correctly when url not exists', () => {
@ -396,12 +396,12 @@ describe('Upload List', () => {
/>,
);
wrapper.find('.ant-upload-list-item-thumbnail').simulate('click');
expect(onPreview).toBeCalled();
expect(onPreview).toHaveBeenCalled();
wrapper.find('.ant-upload-list-item-name').simulate('click');
expect(onPreview).toBeCalled();
expect(onPreview).toHaveBeenCalled();
wrapper.setProps({ items: [{ thumbUrl: 'thumbUrl', uid: 'upload-list-item' }] });
wrapper.find('.ant-upload-list-item-name').simulate('click');
expect(onPreview).toBeCalled();
expect(onPreview).toHaveBeenCalled();
});
it('upload image file should be converted to the base64', done => {
@ -431,6 +431,6 @@ describe('Upload List', () => {
const instance = wrapper.instance();
const callback = jest.fn();
instance.previewFile(mockFile, callback);
expect(callback).toBeCalledWith('');
expect(callback).toHaveBeenCalledWith('');
});
});

1
package.json

@ -127,6 +127,7 @@
"eslint-config-prettier": "^4.0.0",
"eslint-plugin-babel": "^5.2.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jest": "^22.4.1",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-markdown": "~1.0.0-beta.6",
"eslint-plugin-react": "^7.11.1",

6
tests/shared/focusTest.js

@ -26,7 +26,7 @@ export default function focusTest(Component) {
const wrapper = mount(<Component onFocus={handleFocus} />, { attachTo: container });
wrapper.instance().focus();
jest.runAllTimers();
expect(handleFocus).toBeCalled();
expect(handleFocus).toHaveBeenCalled();
});
it('blur() and onBlur', () => {
@ -36,14 +36,14 @@ export default function focusTest(Component) {
jest.runAllTimers();
wrapper.instance().blur();
jest.runAllTimers();
expect(handleBlur).toBeCalled();
expect(handleBlur).toHaveBeenCalled();
});
it('autoFocus', () => {
const handleFocus = jest.fn();
mount(<Component autoFocus onFocus={handleFocus} />, { attachTo: container });
jest.runAllTimers();
expect(handleFocus).toBeCalled();
expect(handleFocus).toHaveBeenCalled();
});
});
}

Loading…
Cancel
Save