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

This commit is contained in:
偏右 2019-04-03 15:54:26 +08:00 committed by zombieJ
parent fc8977b627
commit ad99b4322d
45 changed files with 165 additions and 150 deletions

View File

@ -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,

View File

@ -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();

View File

@ -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', () => {

View File

@ -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', () => {

View File

@ -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();
});
});

View File

@ -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();

View File

@ -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');
});
});

View File

@ -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', () => {

View File

@ -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);
});
});

View File

@ -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.",
);
});

View File

@ -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');
});
});

View File

@ -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();

View File

@ -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', () => {

View File

@ -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', () => {

View File

@ -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');

View File

@ -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();

View File

@ -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', () => {

View File

@ -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.",
);
});

View File

@ -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',

View File

@ -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();
});
});

View File

@ -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);
});
});

View File

@ -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

View File

@ -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 ');
});

View File

@ -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();
});
});

View File

@ -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();
});
});

View File

@ -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]({

View File

@ -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', () => {

View File

@ -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', () => {

View File

@ -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();
});
});

View File

@ -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);
});

View File

@ -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

View File

@ -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

View File

@ -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.',
);
});

View File

@ -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');
});
});

View File

@ -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);

View File

@ -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.',
);
});

View File

@ -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);
});
});

View File

@ -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();

View File

@ -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();
});
});

View File

@ -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', () => {

View File

@ -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();
},
);

View File

@ -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();

View File

@ -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('');
});
});

View File

@ -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",

View File

@ -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();
});
});
}