From 7503caeb1859fb45ec2f4a126da1ad5b51f69aff Mon Sep 17 00:00:00 2001
From: chrismorison-wt <104949709+chrismorison-wt@users.noreply.github.com>
Date: Thu, 20 Oct 2022 14:52:58 +1300
Subject: [PATCH 01/27] docs: fix docs for Alert closeIcon prop. Fixes #38123
(#38124)
---
components/alert/index.en-US.md | 2 +-
components/alert/index.zh-CN.md | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/components/alert/index.en-US.md b/components/alert/index.en-US.md
index 8b8992206b..982057c3cd 100644
--- a/components/alert/index.en-US.md
+++ b/components/alert/index.en-US.md
@@ -21,7 +21,7 @@ Alert component for feedback.
| banner | Whether to show as banner | boolean | false | |
| closable | Whether Alert can be closed | boolean | - | |
| closeText | Close text to show | ReactNode | - | |
-| closeIcon | Custom close icon | ReactNode | `` | 4.17.0 |
+| closeIcon | Custom close icon | ReactNode | `` | 4.18.0 |
| description | Additional content of Alert | ReactNode | - | |
| icon | Custom icon, effective when `showIcon` is true | ReactNode | - | |
| message | Content of Alert | ReactNode | - | |
diff --git a/components/alert/index.zh-CN.md b/components/alert/index.zh-CN.md
index 8946f08330..ee0a63de85 100644
--- a/components/alert/index.zh-CN.md
+++ b/components/alert/index.zh-CN.md
@@ -22,7 +22,7 @@ cover: https://gw.alipayobjects.com/zos/alicdn/8emPa3fjl/Alert.svg
| banner | 是否用作顶部公告 | boolean | false | |
| closable | 默认不显示关闭按钮 | boolean | - | |
| closeText | 自定义关闭按钮 | ReactNode | - | |
-| closeIcon | 自定义关闭 Icon | ReactNode | `` | 4.17.0 |
+| closeIcon | 自定义关闭 Icon | ReactNode | `` | 4.18.0 |
| description | 警告提示的辅助性文字介绍 | ReactNode | - | |
| icon | 自定义图标,`showIcon` 为 true 时有效 | ReactNode | - | |
| message | 警告提示内容 | ReactNode | - | |
From 769cb3c79ad94fc175cf214d188d1eff8b7a9376 Mon Sep 17 00:00:00 2001
From: lijianan <574980606@qq.com>
Date: Thu, 20 Oct 2022 16:37:35 +0800
Subject: [PATCH 02/27] style: remove repeate method (#38133)
* style: remove repeate method
* fix: del break
---
components/_util/reactNode.ts | 2 +-
components/button/button.tsx | 8 ++------
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/components/_util/reactNode.ts b/components/_util/reactNode.ts
index 38e23ee422..8e5b73c016 100644
--- a/components/_util/reactNode.ts
+++ b/components/_util/reactNode.ts
@@ -2,7 +2,7 @@ import * as React from 'react';
export const { isValidElement } = React;
-export function isFragment(child: React.ReactElement): boolean {
+export function isFragment(child: any): boolean {
return child && isValidElement(child) && child.type === React.Fragment;
}
diff --git a/components/button/button.tsx b/components/button/button.tsx
index 469383a145..fd1a4ef8dc 100644
--- a/components/button/button.tsx
+++ b/components/button/button.tsx
@@ -7,7 +7,7 @@ import { ConfigContext } from '../config-provider';
import DisabledContext from '../config-provider/DisabledContext';
import type { SizeType } from '../config-provider/SizeContext';
import SizeContext from '../config-provider/SizeContext';
-import { cloneElement } from '../_util/reactNode';
+import { cloneElement, isFragment } from '../_util/reactNode';
import { tuple } from '../_util/type';
import warning from '../_util/warning';
import Wave from '../_util/wave';
@@ -24,10 +24,6 @@ function isUnBorderedButtonType(type: ButtonType | undefined) {
return type === 'text' || type === 'link';
}
-function isReactFragment(node: React.ReactNode) {
- return React.isValidElement(node) && node.type === React.Fragment;
-}
-
// Insert one space between two chinese characters automatically.
function insertSpace(child: React.ReactElement | string | number, needInserted: boolean) {
// Check the child if is undefined or null.
@@ -49,7 +45,7 @@ function insertSpace(child: React.ReactElement | string | number, needInserted:
if (typeof child === 'string') {
return isTwoCNChar(child) ? {child.split('').join(SPACE)} : {child};
}
- if (isReactFragment(child)) {
+ if (isFragment(child)) {
return {child};
}
return child;
From 3eff12dd69a83be3eb941f3be65c3d5d616afa56 Mon Sep 17 00:00:00 2001
From: zty
Date: Thu, 20 Oct 2022 18:05:29 +0800
Subject: [PATCH 03/27] docs: fix demo code (#38136)
* docs: fix demo code
* docs: fix demo code
* docs: fix demo code
---
docs/react/practical-projects.en-US.md | 25 ++++++++++++-------------
docs/react/practical-projects.zh-CN.md | 16 ++++++----------
2 files changed, 18 insertions(+), 23 deletions(-)
diff --git a/docs/react/practical-projects.en-US.md b/docs/react/practical-projects.en-US.md
index b94699ad91..08911ea7da 100644
--- a/docs/react/practical-projects.en-US.md
+++ b/docs/react/practical-projects.en-US.md
@@ -68,10 +68,13 @@ Let's create a `ProductList` component that we can use in multiple places to sho
Create `src/components/ProductList.tsx` by typing:
-```js
+```tsx
import { Table, Popconfirm, Button } from 'antd';
-const ProductList = ({ onDelete, products }) => {
+const ProductList: React.FC<{ products: { name: string }[]; onDelete: (id: string) => void }> = ({
+ onDelete,
+ products,
+}) => {
const columns = [
{
title: 'Name',
@@ -112,16 +115,12 @@ export function queryProductList() {
export function queryProductList() {
return new Promise(resolve => {
setTimeout(() => {
- resolve([
- {
- id: 1,
- name: 'dva',
- },
- {
- id: 2,
- name: 'antd',
- },
- ]);
+ resolve({
+ data: [
+ { id: 1, name: 'dva' },
+ { id: 2, name: 'antd' },
+ ],
+ });
}, 2000);
});
}
@@ -134,7 +133,7 @@ import { useRequest } from 'umi';
import { queryProductList } from '@/services/product';
export default function useProductList(params: { pageSize: number; current: number }) {
- const msg = useRequest(() => queryUserList(params));
+ const msg = useRequest(() => queryProductList(params));
const deleteProducts = async (id: string) => {
try {
diff --git a/docs/react/practical-projects.zh-CN.md b/docs/react/practical-projects.zh-CN.md
index 4751ce6ee9..dc15c52a11 100644
--- a/docs/react/practical-projects.zh-CN.md
+++ b/docs/react/practical-projects.zh-CN.md
@@ -109,16 +109,12 @@ export function queryProductList() {
export function queryProductList() {
return new Promise(resolve => {
setTimeout(() => {
- resolve([
- {
- id: 1,
- name: 'dva',
- },
- {
- id: 2,
- name: 'antd',
- },
- ]);
+ resolve({
+ data: [
+ { id: 1, name: 'dva' },
+ { id: 2, name: 'antd' },
+ ],
+ });
}, 2000);
});
}
From 3d33c340103152c7af9157d0023dd1c7db9cab62 Mon Sep 17 00:00:00 2001
From: lijianan <574980606@qq.com>
Date: Fri, 21 Oct 2022 11:45:55 +0800
Subject: [PATCH 04/27] chore: use includes instead indexOf (#38139)
* chore: use includes instead indexOf
* fix: fix
---
components/_util/wave.tsx | 4 ++--
components/badge/utils.tsx | 2 +-
components/checkbox/Checkbox.tsx | 2 +-
components/checkbox/Group.tsx | 4 ++--
components/form/util.ts | 2 +-
components/progress/progress.tsx | 4 ++--
components/statistic/utils.tsx | 2 +-
components/table/Table.tsx | 4 ++--
components/transfer/ListBody.tsx | 4 ++--
components/transfer/index.tsx | 12 ++++++------
components/transfer/list.tsx | 4 ++--
components/tree/utils/dictUtil.ts | 7 +------
components/typography/Title.tsx | 2 +-
components/typography/__tests__/index.test.tsx | 10 +++++-----
scripts/generate-authors.js | 2 +-
site/theme/template/Color/Palette.jsx | 2 +-
site/theme/template/Content/index.jsx | 2 +-
17 files changed, 32 insertions(+), 37 deletions(-)
diff --git a/components/_util/wave.tsx b/components/_util/wave.tsx
index 0569966e55..172c35f2ff 100644
--- a/components/_util/wave.tsx
+++ b/components/_util/wave.tsx
@@ -87,7 +87,7 @@ class Wave extends React.Component {
onClick = (node: HTMLElement, waveColor: string) => {
const { insertExtraNode, disabled } = this.props;
- if (disabled || !node || isHidden(node) || node.className.indexOf('-leave') >= 0) {
+ if (disabled || !node || isHidden(node) || node.className.includes('-leave')) {
return;
}
@@ -163,7 +163,7 @@ class Wave extends React.Component {
!node ||
!node.getAttribute ||
node.getAttribute('disabled') ||
- node.className.indexOf('disabled') >= 0
+ node.className.includes('disabled')
) {
return;
}
diff --git a/components/badge/utils.tsx b/components/badge/utils.tsx
index ada1c6580c..2c9a500e88 100644
--- a/components/badge/utils.tsx
+++ b/components/badge/utils.tsx
@@ -2,5 +2,5 @@ import { PresetColorTypes } from '../_util/colors';
// eslint-disable-next-line import/prefer-default-export
export function isPresetColor(color?: string): boolean {
- return (PresetColorTypes as any[]).indexOf(color) !== -1;
+ return (PresetColorTypes as any[]).includes(color);
}
diff --git a/components/checkbox/Checkbox.tsx b/components/checkbox/Checkbox.tsx
index bed9a7e975..03449860d0 100644
--- a/components/checkbox/Checkbox.tsx
+++ b/components/checkbox/Checkbox.tsx
@@ -102,7 +102,7 @@ const InternalCheckbox: React.ForwardRefRenderFunction registeredValues.indexOf(val) !== -1)
+ .filter(val => registeredValues.includes(val))
.sort((a, b) => {
const indexA = opts.findIndex(opt => opt.value === a);
const indexB = opts.findIndex(opt => opt.value === b);
@@ -122,7 +122,7 @@ const InternalCheckboxGroup: React.ForwardRefRenderFunction= 0;
+ const isIllegalName = formItemNameBlackList.includes(mergedId);
return isIllegalName ? `${defaultItemNamePrefixCls}_${mergedId}` : mergedId;
}
diff --git a/components/progress/progress.tsx b/components/progress/progress.tsx
index e0bb06a3e9..3d995b9440 100644
--- a/components/progress/progress.tsx
+++ b/components/progress/progress.tsx
@@ -75,7 +75,7 @@ const Progress: React.FC = (props: ProgressProps) => {
function getProgressStatus() {
const { status } = props;
- if (ProgressStatuses.indexOf(status!) < 0 && getPercentNumber() >= 100) {
+ if (!ProgressStatuses.includes(status!) && getPercentNumber() >= 100) {
return 'success';
}
return status || 'normal';
@@ -119,7 +119,7 @@ const Progress: React.FC = (props: ProgressProps) => {
const strokeColorNotArray = Array.isArray(strokeColor) ? strokeColor[0] : strokeColor;
const strokeColorNotGradient =
typeof strokeColor === 'string' || Array.isArray(strokeColor) ? strokeColor : undefined;
- let progress;
+ let progress: React.ReactNode;
// Render progress shape
if (type === 'line') {
progress = steps ? (
diff --git a/components/statistic/utils.tsx b/components/statistic/utils.tsx
index 600abbe27f..91027740f4 100644
--- a/components/statistic/utils.tsx
+++ b/components/statistic/utils.tsx
@@ -41,7 +41,7 @@ export function formatTimeStr(duration: number, format: string) {
const templateText = format.replace(escapeRegex, '[]');
const replacedText = timeUnits.reduce((current, [name, unit]) => {
- if (current.indexOf(name) !== -1) {
+ if (current.includes(name)) {
const value = Math.floor(leftDuration / unit);
leftDuration -= value * unit;
return current.replace(new RegExp(`${name}+`, 'g'), (match: string) => {
diff --git a/components/table/Table.tsx b/components/table/Table.tsx
index d08d1a5fb2..1c378c5ab7 100644
--- a/components/table/Table.tsx
+++ b/components/table/Table.tsx
@@ -482,8 +482,8 @@ function InternalTable(
const defaultPosition = direction === 'rtl' ? 'left' : 'right';
const { position } = mergedPagination;
if (position !== null && Array.isArray(position)) {
- const topPos = position.find(p => p.indexOf('top') !== -1);
- const bottomPos = position.find(p => p.indexOf('bottom') !== -1);
+ const topPos = position.find(p => p.includes('top'));
+ const bottomPos = position.find(p => p.includes('bottom'));
const isDisable = position.every(p => `${p}` === 'none');
if (!topPos && !bottomPos && !isDisable) {
bottomPaginationNode = renderPagination(defaultPosition);
diff --git a/components/transfer/ListBody.tsx b/components/transfer/ListBody.tsx
index d111f30f2b..e5f57703c3 100644
--- a/components/transfer/ListBody.tsx
+++ b/components/transfer/ListBody.tsx
@@ -71,7 +71,7 @@ class ListBody extends React.Component<
onItemSelect = (item: RecordType) => {
const { onItemSelect, selectedKeys } = this.props;
- const checked = selectedKeys.indexOf(item.key) >= 0;
+ const checked = selectedKeys.includes(item.key);
onItemSelect(item.key, !checked);
};
@@ -144,7 +144,7 @@ class ListBody extends React.Component<
>
{this.getItems().map(({ renderedEl, renderedText, item }: RenderedItem) => {
const { disabled } = item;
- const checked = selectedKeys.indexOf(item.key) >= 0;
+ const checked = selectedKeys.includes(item.key);
return (
extends React.Com
const { selectedKeys = [], targetKeys = [] } = props;
this.state = {
- sourceSelectedKeys: selectedKeys.filter(key => targetKeys.indexOf(key) === -1),
- targetSelectedKeys: selectedKeys.filter(key => targetKeys.indexOf(key) > -1),
+ sourceSelectedKeys: selectedKeys.filter(key => !targetKeys.includes(key)),
+ targetSelectedKeys: selectedKeys.filter(key => targetKeys.includes(key)),
};
}
@@ -198,7 +198,7 @@ class Transfer extends React.Com
const newTargetKeys =
direction === 'right'
? newMoveKeys.concat(targetKeys)
- : targetKeys.filter(targetKey => newMoveKeys.indexOf(targetKey) === -1);
+ : targetKeys.filter(targetKey => !newMoveKeys.includes(targetKey));
// empty checked keys
const oppositeDirection = direction === 'right' ? 'left' : 'right';
@@ -214,13 +214,13 @@ class Transfer extends React.Com
onItemSelectAll = (direction: TransferDirection, selectedKeys: string[], checkAll: boolean) => {
this.setStateKeys(direction, prevKeys => {
- let mergedCheckedKeys = [];
+ let mergedCheckedKeys: string[] = [];
if (checkAll) {
// Merge current keys with origin key
- mergedCheckedKeys = Array.from(new Set([...prevKeys, ...selectedKeys]));
+ mergedCheckedKeys = Array.from(new Set([...prevKeys, ...selectedKeys]));
} else {
// Remove current keys from origin keys
- mergedCheckedKeys = prevKeys.filter((key: string) => selectedKeys.indexOf(key) === -1);
+ mergedCheckedKeys = prevKeys.filter(key => !selectedKeys.includes(key));
}
this.handleSelectChange(direction, mergedCheckedKeys);
diff --git a/components/transfer/list.tsx b/components/transfer/list.tsx
index 00f9b5c685..a6e132b64d 100644
--- a/components/transfer/list.tsx
+++ b/components/transfer/list.tsx
@@ -109,7 +109,7 @@ export default class TransferList<
if (checkedKeys.length === 0) {
return 'none';
}
- if (filteredItems.every(item => checkedKeys.indexOf(item.key) >= 0 || !!item.disabled)) {
+ if (filteredItems.every(item => checkedKeys.includes(item.key) || !!item.disabled)) {
return 'all';
}
return 'part';
@@ -161,7 +161,7 @@ export default class TransferList<
if (filterOption) {
return filterOption(filterValue, item);
}
- return text.indexOf(filterValue) >= 0;
+ return text.includes(filterValue);
};
// =============================== Render ===============================
diff --git a/components/tree/utils/dictUtil.ts b/components/tree/utils/dictUtil.ts
index f1411c6a7e..bc6cfa0343 100644
--- a/components/tree/utils/dictUtil.ts
+++ b/components/tree/utils/dictUtil.ts
@@ -65,12 +65,7 @@ export function calcRangeKeys({
// Append selection
keys.push(key);
}
-
- if (expandedKeys.indexOf(key) === -1) {
- return false;
- }
-
- return true;
+ return expandedKeys.includes(key);
});
return keys;
diff --git a/components/typography/Title.tsx b/components/typography/Title.tsx
index 2e0ab33b1d..1cd1f84246 100644
--- a/components/typography/Title.tsx
+++ b/components/typography/Title.tsx
@@ -19,7 +19,7 @@ const Title = React.forwardRef((props, ref) => {
const { level = 1, ...restProps } = props;
let component: keyof JSX.IntrinsicElements;
- if (TITLE_ELE_LIST.indexOf(level) !== -1) {
+ if (TITLE_ELE_LIST.includes(level)) {
component = `h${level}`;
} else {
warning(
diff --git a/components/typography/__tests__/index.test.tsx b/components/typography/__tests__/index.test.tsx
index 703efec890..ab2f767f24 100644
--- a/components/typography/__tests__/index.test.tsx
+++ b/components/typography/__tests__/index.test.tsx
@@ -262,14 +262,14 @@ describe('Typography', () => {
,
);
- if (triggerType === undefined || triggerType.indexOf('icon') !== -1) {
+ if (triggerType === undefined || triggerType.includes('icon')) {
if (icon) {
expect(wrapper.querySelectorAll('.anticon-highlight').length).toBeGreaterThan(0);
} else {
expect(wrapper.querySelectorAll('.anticon-edit').length).toBeGreaterThan(0);
}
- if (triggerType === undefined || triggerType.indexOf('text') === -1) {
+ if (triggerType === undefined || !triggerType.includes('text')) {
fireEvent.click(wrapper.firstChild!);
expect(onStart).not.toHaveBeenCalled();
}
@@ -295,15 +295,15 @@ describe('Typography', () => {
fireEvent.click(wrapper.querySelectorAll('.ant-typography-edit')[0]);
expect(onStart).toHaveBeenCalled();
- if (triggerType !== undefined && triggerType.indexOf('text') !== -1) {
+ if (triggerType !== undefined && triggerType.includes('text')) {
fireEvent.keyDown(wrapper.querySelector('textarea')!, { keyCode: KeyCode.ESC });
fireEvent.keyUp(wrapper.querySelector('textarea')!, { keyCode: KeyCode.ESC });
expect(onChange).not.toHaveBeenCalled();
}
}
- if (triggerType !== undefined && triggerType.indexOf('text') !== -1) {
- if (triggerType.indexOf('icon') === -1) {
+ if (triggerType !== undefined && triggerType.includes('text')) {
+ if (!triggerType.includes('icon')) {
expect(wrapper.querySelectorAll('.anticon-highlight').length).toBe(0);
expect(wrapper.querySelectorAll('.anticon-edit').length).toBe(0);
}
diff --git a/scripts/generate-authors.js b/scripts/generate-authors.js
index 02ede750bd..716ecf8637 100644
--- a/scripts/generate-authors.js
+++ b/scripts/generate-authors.js
@@ -21,7 +21,7 @@ async function execute() {
logs = _.remove(logs, ({ author_email: email }) => {
for (let i = 0; i < excludes.length; i++) {
const item = excludes[i];
- if (email.indexOf(item) !== -1) {
+ if (email.includes(item)) {
return false;
}
}
diff --git a/site/theme/template/Color/Palette.jsx b/site/theme/template/Color/Palette.jsx
index f7bbb6ac49..cfff5d67ca 100644
--- a/site/theme/template/Color/Palette.jsx
+++ b/site/theme/template/Color/Palette.jsx
@@ -19,7 +19,7 @@ export default class Palette extends React.Component {
this.hexColors = {};
Object.keys(this.colorNodes).forEach(key => {
const computedColor = getComputedStyle(this.colorNodes[key])['background-color'];
- if (computedColor.indexOf('rgba') >= 0) {
+ if (computedColor.includes('rgba')) {
this.hexColors[key] = computedColor;
} else {
this.hexColors[key] = rgbToHex(computedColor);
diff --git a/site/theme/template/Content/index.jsx b/site/theme/template/Content/index.jsx
index b5129b4215..8e5a7b3c04 100644
--- a/site/theme/template/Content/index.jsx
+++ b/site/theme/template/Content/index.jsx
@@ -3,7 +3,7 @@ import MainContent from './MainContent';
import * as utils from '../utils';
function isChangelog(pathname) {
- return pathname.indexOf('changelog') >= 0;
+ return pathname.includes('changelog');
}
export default collect(async nextProps => {
From be1a51e5fc7aeba4a6bcd8ed2748bf90080507ad Mon Sep 17 00:00:00 2001
From: hms181231
Date: Fri, 21 Oct 2022 15:06:11 +0800
Subject: [PATCH 05/27] test: Update form test case (#38143)
---
components/form/__tests__/list.test.tsx | 117 +++++++++++++-----------
1 file changed, 65 insertions(+), 52 deletions(-)
diff --git a/components/form/__tests__/list.test.tsx b/components/form/__tests__/list.test.tsx
index 0010d782f7..671ada9994 100644
--- a/components/form/__tests__/list.test.tsx
+++ b/components/form/__tests__/list.test.tsx
@@ -1,27 +1,59 @@
import React from 'react';
import type { FormListFieldData, FormListOperation } from '..';
import Form from '..';
-import { fireEvent, render, sleep, act } from '../../../tests/utils';
+import { fireEvent, render, waitFakeTimer } from '../../../tests/utils';
import Button from '../../button';
import Input from '../../input';
describe('Form.List', () => {
- const change = async (
- wrapper: ReturnType['container'],
- index: number,
+ // const change = async (
+ // wrapper: ReturnType['container'],
+ // index: number,
+ // value: string,
+ // ) => {
+ // fireEvent.change(wrapper.getElementsByClassName('ant-input')?.[index], { target: { value } });
+ // await sleep();
+ // };
+
+ const changeValue = async (
+ input: HTMLElement | null | number,
value: string,
+ advTimer = 1000,
) => {
- fireEvent.change(wrapper.getElementsByClassName('ant-input')?.[index], { target: { value } });
- await sleep();
+ let element: HTMLElement;
+
+ if (typeof input === 'number') {
+ element = document.querySelectorAll('input')[input];
+ }
+
+ expect(element!).toBeTruthy();
+
+ fireEvent.change(element!, {
+ target: {
+ value,
+ },
+ });
+
+ if (advTimer) {
+ await waitFakeTimer(advTimer / 20);
+ }
};
+ beforeEach(() => {
+ document.body.innerHTML = '';
+ jest.useFakeTimers();
+ });
+
+ afterAll(() => {
+ jest.clearAllTimers();
+ jest.useRealTimers();
+ });
+
const testList = (
name: string,
renderField: (value: FormListFieldData) => React.ReactNode,
): void => {
it(name, async () => {
- jest.useFakeTimers();
-
const { container } = render(
@@ -39,39 +71,31 @@ describe('Form.List', () => {
,
);
- function operate(className: string) {
+ async function operate(className: string) {
fireEvent.click(container.querySelector(className)!);
- act(() => {
- jest.runAllTimers();
- });
+ await waitFakeTimer();
}
- operate('.add');
- expect(container.getElementsByClassName('ant-input').length).toBe(1);
+ await operate('.add');
+ expect(container.querySelectorAll('.ant-input').length).toBe(1);
- operate('.add');
- expect(container.getElementsByClassName('ant-input').length).toBe(2);
+ await operate('.add');
+ expect(container.querySelectorAll('.ant-input').length).toBe(2);
- operate('.add');
- expect(container.getElementsByClassName('ant-input').length).toBe(3);
+ await operate('.add');
+ expect(container.querySelectorAll('.ant-input').length).toBe(3);
- await change(container, 2, '');
- for (let i = 0; i < 10; i += 1) {
- act(() => {
- jest.runAllTimers();
- });
- }
- expect(container.getElementsByClassName('ant-form-item-explain').length).toBe(1);
+ await changeValue(2, '');
- operate('.remove-0');
- expect(container.getElementsByClassName('ant-input').length).toBe(2);
- expect(container.getElementsByClassName('ant-form-item-explain').length).toBe(1);
+ expect(container.querySelectorAll('.ant-form-item-explain').length).toBe(1);
- operate('.remove-1');
- expect(container.getElementsByClassName('ant-input').length).toBe(1);
- expect(container.getElementsByClassName('ant-form-item-explain').length).toBe(0);
+ await operate('.remove-0');
+ expect(container.querySelectorAll('.ant-input').length).toBe(2);
+ expect(container.querySelectorAll('.ant-form-item-explain').length).toBe(1);
- jest.useRealTimers();
+ await operate('.remove-1');
+ expect(container.querySelectorAll('.ant-input').length).toBe(1);
+ expect(container.querySelectorAll('.ant-form-item-explain').length).toBe(0);
});
};
@@ -131,28 +155,26 @@ describe('Form.List', () => {
);
await click(container, '.add');
- await change(container, 0, 'input1');
+ await changeValue(0, 'input1');
fireEvent.submit(container.querySelector('form')!);
- await sleep();
+ await waitFakeTimer();
expect(onFinish).toHaveBeenLastCalledWith({ list: ['input1'] });
await click(container, '.add');
- await change(container, 1, 'input2');
+ await changeValue(1, 'input2');
await click(container, '.add');
- await change(container, 2, 'input3');
+ await changeValue(2, 'input3');
fireEvent.submit(container.querySelector('form')!);
- await sleep();
+ await waitFakeTimer();
expect(onFinish).toHaveBeenLastCalledWith({ list: ['input1', 'input2', 'input3'] });
await click(container, '.remove'); // will remove first input
fireEvent.submit(container.querySelector('form')!);
- await sleep();
+ await waitFakeTimer();
expect(onFinish).toHaveBeenLastCalledWith({ list: ['input2', 'input3'] });
});
it('list errors', async () => {
- jest.useFakeTimers();
-
let operation: FormListOperation;
const { container } = render(