Skip to content

Commit

Permalink
fix: better test style
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed May 25, 2023
1 parent a620938 commit 4811274
Show file tree
Hide file tree
Showing 29 changed files with 448 additions and 450 deletions.
2 changes: 1 addition & 1 deletion tests/field/__snapshots__/field.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ exports[`Field 🐴 edit and no plain 1`] = `
</DocumentFragment>
`;

exports[`Field 🐴 edit and plain 1`] = `
exports[`Field 🐴 edit and plain=true 1`] = `
<DocumentFragment>
<div
class="ant-descriptions"
Expand Down
26 changes: 10 additions & 16 deletions tests/field/field.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { act, fireEvent, render, waitFor } from '@testing-library/react';
import { Button, Input } from 'antd';
import dayjs from 'dayjs';
import React, { useState } from 'react';
import { waitTime } from '../util';
import { waitForWaitTime, waitTime } from '../util';
import Demo from './fixtures/demo';
import { TreeSelectDemo } from './fixtures/treeSelectDemo';

Expand Down Expand Up @@ -970,7 +970,7 @@ describe('Field', () => {
expect(html.asFragment()).toMatchSnapshot();
});

it('🐴 edit and plain', async () => {
it('🐴 edit and plain=true', async () => {
const html = render(<Demo plain state="edit" />);
expect(html.asFragment()).toMatchSnapshot();
});
Expand Down Expand Up @@ -1020,13 +1020,11 @@ describe('Field', () => {
text="1994-07-29 12:00:00"
mode="read"
valueType={valueType as 'text'}
render={() => <>qixian</>}
render={() => <span>qixian</span>}
/>,
);

await waitFor(() => {
expect(html.baseElement.textContent).toBe('qixian');
});
await html.findAllByText('qixian');
expect(html.baseElement.textContent).toBe('qixian');
});

it(`🐴 valueType renderFormItem ${valueType}`, async () => {
Expand All @@ -1036,12 +1034,10 @@ describe('Field', () => {
text={dayjs('2019-11-16 12:50:26').valueOf()}
mode="edit"
valueType={valueType as 'text'}
renderFormItem={() => <>qixian</>}
renderFormItem={() => <span>qixian</span>}
/>,
);
await waitFor(() => {
expect(html.baseElement.textContent).toBe('qixian');
});
await html.findAllByText('qixian');
});

it(`🐴 ${valueType} mode="error"`, async () => {
Expand All @@ -1054,9 +1050,7 @@ describe('Field', () => {
valueType={valueType as 'text'}
/>,
);
await waitFor(() => {
expect(html.baseElement.textContent).toBeFalsy();
});
expect(html.baseElement.textContent).toBeFalsy();
});

it(`🐴 valueType render ${valueType} when text is null`, async () => {
Expand Down Expand Up @@ -1700,7 +1694,7 @@ describe('Field', () => {

it(`🐴 valueType digitRange normal input simulate`, async () => {
const html = render(<Field mode="edit" valueType="digitRange" />);
await waitTime(100);
await waitForWaitTime(100);
act(() => {
fireEvent.change(
html.baseElement.querySelector('.ant-input-number-input')!,
Expand Down Expand Up @@ -1890,7 +1884,7 @@ describe('Field', () => {
]}
/>,
);
await waitTime(100);
await waitForWaitTime(100);

act(() => {
// 点击label打开DatePicker
Expand Down
30 changes: 15 additions & 15 deletions tests/form/base.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import userEvent from '@testing-library/user-event';
import { Button, ConfigProvider, Input } from 'antd';
import dayjs from 'dayjs';
import React, { useEffect, useRef } from 'react';
import { waitTime } from '../util';
import { waitForWaitTime } from '../util';

describe('ProForm', () => {
it('📦 submit props actionsRender=false', async () => {
Expand Down Expand Up @@ -632,7 +632,7 @@ describe('ProForm', () => {
<ProForm onFinish={(values) => onFinish(values.name)}>
<ProFormCaptcha
onGetCaptcha={async () => {
await waitTime(10);
await waitForWaitTime(10);
}}
countDown={2}
label="name"
Expand Down Expand Up @@ -1857,7 +1857,7 @@ describe('ProForm', () => {
value: '门',
},
});
await waitTime(200);
await waitForWaitTime(200);
});

act(() => {
Expand Down Expand Up @@ -1896,7 +1896,7 @@ describe('ProForm', () => {
value: '期贤',
},
});
await waitTime(200);
await waitForWaitTime(200);
});
act(() => {
fireEvent.mouseDown(
Expand Down Expand Up @@ -1969,7 +1969,7 @@ describe('ProForm', () => {
value: '(测试)',
},
});
await waitTime(200);
await waitForWaitTime(200);
});

act(() => {
Expand Down Expand Up @@ -2402,7 +2402,7 @@ describe('ProForm', () => {
</>,
);

await waitTime(100);
await waitForWaitTime(100);

act(() => {
fireEvent.mouseDown(
Expand Down Expand Up @@ -2820,7 +2820,7 @@ describe('ProForm', () => {

const wrapper = render(<App />);

await waitTime(200);
await waitForWaitTime(200);
expect(fn1).toHaveBeenCalledWith('2021-08-09');

act(() => {
Expand All @@ -2829,7 +2829,7 @@ describe('ProForm', () => {
.click();
});

await waitTime(200);
await waitForWaitTime(200);

expect(fn2).toHaveBeenCalledWith('2021-08-03');

Expand Down Expand Up @@ -3085,7 +3085,7 @@ describe('ProForm', () => {
</ProForm>,
);

await waitTime(300);
await waitForWaitTime(300);
act(() => {
const dom =
html.baseElement.querySelector<HTMLInputElement>('input#count')!;
Expand All @@ -3097,7 +3097,7 @@ describe('ProForm', () => {
fireEvent.blur(dom);
fireEvent.click(dom);
});
await waitTime(300);
await waitForWaitTime(300);
expect(
html.baseElement.querySelector<HTMLInputElement>('input#count')?.value,
).toBe('22');
Expand Down Expand Up @@ -3129,14 +3129,14 @@ describe('ProForm', () => {
</ProForm>,
);

await waitTime(300);
await waitForWaitTime(300);

const dom =
html.baseElement.querySelector<HTMLInputElement>('input#count')!;
await userEvent.type(dom, '22.22.22');
await userEvent.click(await html.findByText('提 交'));

await waitTime(300);
await waitForWaitTime(300);

expect(dom.value).toBe('22');
expect(fn).toBeCalledWith(22);
Expand Down Expand Up @@ -3259,7 +3259,7 @@ describe('ProForm', () => {
</ProForm>,
);

await waitTime(100);
await waitForWaitTime(100);

act(() => {
fireEvent.change(
Expand All @@ -3273,14 +3273,14 @@ describe('ProForm', () => {
},
);
});
await waitTime(100);
await waitForWaitTime(100);
act(() => {
fireEvent.mouseDown(
wrapper.baseElement.querySelectorAll('.ant-select-selector')[0],
{},
);
});
await waitTime(100);
await waitForWaitTime(100);
expect(onRequest.mock.calls.length).toBe(3);
wrapper.unmount();
});
Expand Down
14 changes: 7 additions & 7 deletions tests/form/dependency.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ProFormText,
} from '@ant-design/pro-components';
import { act, fireEvent, render } from '@testing-library/react';
import { waitTime } from '../util';
import { waitForWaitTime } from '../util';

describe('ProForm Dependency component', () => {
it('⛲ shouldUpdate of ProFormDependency is Boolean', async () => {
Expand Down Expand Up @@ -36,7 +36,7 @@ describe('ProForm Dependency component', () => {
);
});

await waitTime(100);
await waitForWaitTime(100);

expect(
html.baseElement.querySelector<HTMLDivElement>('div#show')?.textContent,
Expand All @@ -46,7 +46,7 @@ describe('ProForm Dependency component', () => {
html.rerender(<Demo shouldUpdate />);
});

await waitTime(100);
await waitForWaitTime(100);

act(() => {
fireEvent.change(
Expand All @@ -59,7 +59,7 @@ describe('ProForm Dependency component', () => {
);
});

await waitTime(100);
await waitForWaitTime(100);

expect(
html.baseElement.querySelector<HTMLDivElement>('div#show')?.textContent,
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('ProForm Dependency component', () => {
);
});

await waitTime(100);
await waitForWaitTime(100);

act(() => {
fireEvent.change(
Expand All @@ -110,7 +110,7 @@ describe('ProForm Dependency component', () => {
);
});

await waitTime(100);
await waitForWaitTime(100);

expect(
html.baseElement.querySelector<HTMLDivElement>('div#show')?.textContent,
Expand Down Expand Up @@ -157,7 +157,7 @@ describe('ProForm Dependency component', () => {
);
});

await waitTime(100);
await waitForWaitTime(100);
expect(dependencyFn).toBeCalledWith('second chen');
});
});
Loading

0 comments on commit 4811274

Please sign in to comment.