Skip to content

Commit 8e20d26

Browse files
committed
fix test
1 parent 52ed901 commit 8e20d26

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+661
-636
lines changed

pnpm-lock.yaml

+212-198
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/card/checkcard.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('CheckCard', () => {
3333
*/
3434
await waitFor(() => {
3535
// 断言 onChange 回调函数已被调用,并且传入参数为 true。
36-
expect(onChange).toBeCalledWith(true);
36+
expect(onChange).toHaveBeenCalledWith(true);
3737
// 断言 onClick 回调函数已被调用。
3838
expect(onClick).toHaveBeenCalled();
3939
});

tests/card/index.test.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ProCard } from '@ant-design/pro-components';
2-
import { act, cleanup, render } from '@testing-library/react';
2+
import { act, cleanup, render, waitFor } from '@testing-library/react';
33

44
vi.mock('antd/lib/grid/hooks/useBreakpoint');
55

@@ -37,7 +37,9 @@ describe('Card', () => {
3737
?.click();
3838
});
3939

40-
expect(fn).toBeCalled();
40+
await waitFor(() => {
41+
expect(fn).toHaveBeenCalled();
42+
});
4143
});
4244

4345
it('🥩 collapsible defaultCollapsed', async () => {

tests/demo.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ function demoTest(component: string, options?: Options) {
125125
});
126126

127127
await waitFor(() => {
128-
expect(fn).toBeCalled();
128+
expect(fn).toHaveBeenCalled();
129129
});
130+
130131
await waitFor(() => {
131132
expect(wrapper.asFragment()).toMatchSnapshot();
132133
});
133-
134134
wrapper.unmount();
135135
vi.useRealTimers();
136136
cleanup();

tests/descriptions/editor.test.tsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ describe('Descriptions', () => {
198198
});
199199

200200
await waitFor(() => {
201-
expect(fn).toBeCalledWith(['title']);
201+
expect(fn).toHaveBeenCalledWith(['title']);
202202
});
203203
});
204204

@@ -437,7 +437,7 @@ describe('Descriptions', () => {
437437
});
438438

439439
await waitFor(() => {
440-
expect(fn).not.toBeCalled();
440+
expect(fn).not.toHaveBeenCalled();
441441
});
442442
});
443443

@@ -459,7 +459,7 @@ describe('Descriptions', () => {
459459
?.click();
460460
});
461461
await waitFor(() => {
462-
expect(fn).toBeCalledWith(['state', 'title']);
462+
expect(fn).toHaveBeenCalledWith(['state', 'title']);
463463
});
464464
});
465465

@@ -492,7 +492,7 @@ describe('Descriptions', () => {
492492
?.click();
493493
});
494494
await waitFor(() => {
495-
expect(fn).toBeCalledWith('state');
495+
expect(fn).toHaveBeenCalledWith('state');
496496
});
497497
});
498498

@@ -545,7 +545,7 @@ describe('Descriptions', () => {
545545
});
546546

547547
await waitFor(() => {
548-
expect(fn).toBeCalledWith('state');
548+
expect(fn).toHaveBeenCalledWith('state');
549549
});
550550
});
551551

@@ -580,7 +580,7 @@ describe('Descriptions', () => {
580580
});
581581

582582
await waitFor(() => {
583-
expect(fn).toBeCalledWith('state');
583+
expect(fn).toHaveBeenCalledWith('state');
584584
});
585585
});
586586

@@ -633,7 +633,7 @@ describe('Descriptions', () => {
633633

634634
await waitFor(() => {
635635
// 没有通过验证,不触发 onSave
636-
expect(fn).not.toBeCalled();
636+
expect(fn).not.toHaveBeenCalled();
637637
});
638638

639639
act(() => {
@@ -663,7 +663,7 @@ describe('Descriptions', () => {
663663
});
664664

665665
await waitFor(() => {
666-
expect(fn).toBeCalledWith('qixian');
666+
expect(fn).toHaveBeenCalledWith('qixian');
667667
});
668668
});
669669

@@ -705,7 +705,7 @@ describe('Descriptions', () => {
705705
});
706706

707707
await waitFor(() => {
708-
expect(fn).toBeCalledWith('2021-05-26 09:42:56');
708+
expect(fn).toHaveBeenCalledWith('2021-05-26 09:42:56');
709709
});
710710
});
711711
});

tests/descriptions/index.test.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('descriptions', () => {
6363
);
6464

6565
await waitFor(() => {
66-
expect(fn).toBeCalled();
66+
expect(fn).toHaveBeenCalled();
6767
});
6868
});
6969

@@ -190,7 +190,7 @@ describe('descriptions', () => {
190190

191191
await html.findAllByText('这是一段文本');
192192
await waitFor(() => {
193-
expect(fn).toBeCalledTimes(1);
193+
expect(fn).toHaveBeenCalledTimes(1);
194194
});
195195
act(() => {
196196
html.queryByText('刷新')?.click();
@@ -204,7 +204,7 @@ describe('descriptions', () => {
204204

205205
await waitFor(() => {
206206
// 因为有 loading 的控制,所有只会触发两次
207-
expect(fn).toBeCalledTimes(2);
207+
expect(fn).toHaveBeenCalledTimes(2);
208208
});
209209

210210
vi.useRealTimers();
@@ -246,7 +246,7 @@ describe('descriptions', () => {
246246
});
247247

248248
await waitFor(() => {
249-
expect(fn).toBeCalledTimes(1);
249+
expect(fn).toHaveBeenCalledTimes(1);
250250
});
251251

252252
act(() => {
@@ -289,7 +289,7 @@ describe('descriptions', () => {
289289
await html.findAllByText('这是一段文本');
290290

291291
await waitFor(() => {
292-
expect(fn).toBeCalledTimes(2);
292+
expect(fn).toHaveBeenCalledTimes(2);
293293
});
294294

295295
vi.useRealTimers();
@@ -322,7 +322,7 @@ describe('descriptions', () => {
322322
);
323323

324324
await waitFor(() => {
325-
expect(fn).toBeCalledTimes(1);
325+
expect(fn).toHaveBeenCalledTimes(1);
326326
});
327327
});
328328

tests/field/datePick.test.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ describe('DateField', () => {
6262
});
6363

6464
await waitFor(() => {
65-
expect(openChangeFn).toBeCalledWith(true);
65+
expect(openChangeFn).toHaveBeenCalledWith(true);
6666
});
6767

6868
act(() => {
6969
closePicker(container);
7070
});
7171

7272
await waitFor(() => {
73-
expect(openChangeFn).toBeCalledWith(false);
73+
expect(openChangeFn).toHaveBeenCalledWith(false);
7474
});
7575
await act(async () => {
7676
await fireEvent.click(container.querySelector('.ant-picker-clear')!);
@@ -80,7 +80,7 @@ describe('DateField', () => {
8080

8181
await waitFor(
8282
() => {
83-
expect(fn).toBeCalled();
83+
expect(fn).toHaveBeenCalled();
8484
},
8585
{
8686
timeout: 1000,
@@ -124,7 +124,7 @@ describe('DateField', () => {
124124
});
125125

126126
await waitFor(() => {
127-
expect(openChangeFn).toBeCalledWith(true);
127+
expect(openChangeFn).toHaveBeenCalledWith(true);
128128
});
129129

130130
act(() => {
@@ -141,12 +141,12 @@ describe('DateField', () => {
141141
});
142142

143143
await waitFor(() => {
144-
expect(openChangeFn).toBeCalledWith(false);
144+
expect(openChangeFn).toHaveBeenCalledWith(false);
145145
});
146146

147147
await waitFor(
148148
() => {
149-
expect(onChangeFn).toBeCalled();
149+
expect(onChangeFn).toHaveBeenCalled();
150150
},
151151
{
152152
timeout: 1000,

tests/field/field.test.tsx

+15-15
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,15 @@ describe('Field', () => {
202202
});
203203
});
204204

205-
expect(fn).toBeCalled();
205+
expect(fn).toHaveBeenCalled();
206206

207207
act(() => {
208208
fireEvent.blur(html.baseElement.querySelector('input')!, {
209209
target: { value: 1000 },
210210
});
211211
});
212212

213-
expect(fn).toBeCalledTimes(2);
213+
expect(fn).toHaveBeenCalledTimes(2);
214214

215215
html.unmount();
216216
});
@@ -350,7 +350,7 @@ describe('Field', () => {
350350

351351
await html.findAllByText('default');
352352

353-
expect(fn).toBeCalledTimes(1);
353+
expect(fn).toHaveBeenCalledTimes(1);
354354

355355
act(() => {
356356
ref.current?.fetchData?.('test');
@@ -360,7 +360,7 @@ describe('Field', () => {
360360
vi.runOnlyPendingTimers();
361361
});
362362

363-
expect(fn).toBeCalledTimes(2);
363+
expect(fn).toHaveBeenCalledTimes(2);
364364
html.unmount();
365365
vi.useRealTimers();
366366
});
@@ -627,7 +627,7 @@ describe('Field', () => {
627627
});
628628

629629
await waitFor(() => {
630-
expect(fn).toBeCalledWith(true);
630+
expect(fn).toHaveBeenCalledWith(true);
631631
});
632632

633633
act(() => {
@@ -637,7 +637,7 @@ describe('Field', () => {
637637
});
638638

639639
await waitFor(() => {
640-
expect(fn).toBeCalledWith(false);
640+
expect(fn).toHaveBeenCalledWith(false);
641641
});
642642
});
643643
});
@@ -907,7 +907,7 @@ describe('Field', () => {
907907
});
908908

909909
await waitFor(() => {
910-
expect(requestFn).toBeCalledTimes(1);
910+
expect(requestFn).toHaveBeenCalledTimes(1);
911911
});
912912

913913
await html.findAllByText('Node2');
@@ -955,7 +955,7 @@ describe('Field', () => {
955955
});
956956

957957
await waitFor(() => {
958-
expect(onSearchFn).toBeCalled();
958+
expect(onSearchFn).toHaveBeenCalled();
959959
});
960960

961961
act(() => {
@@ -1011,7 +1011,7 @@ describe('Field', () => {
10111011
});
10121012

10131013
await waitFor(() => {
1014-
expect(onClearFn).toBeCalled();
1014+
expect(onClearFn).toHaveBeenCalled();
10151015
expect(html.baseElement.textContent).toContain('');
10161016
});
10171017

@@ -1024,7 +1024,7 @@ describe('Field', () => {
10241024
);
10251025
});
10261026

1027-
expect(onBlurFn).toBeCalledTimes(1);
1027+
expect(onBlurFn).toHaveBeenCalledTimes(1);
10281028
html.unmount();
10291029
vi.useRealTimers();
10301030
});
@@ -1505,7 +1505,7 @@ describe('Field', () => {
15051505
expect(
15061506
!!html.baseElement.querySelector('span.anticon-eye-invisible'),
15071507
).toBeFalsy();
1508-
expect(fn).toBeCalledWith(false);
1508+
expect(fn).toHaveBeenCalledWith(false);
15091509
});
15101510

15111511
html.unmount();
@@ -1532,7 +1532,7 @@ describe('Field', () => {
15321532
expect(
15331533
!!html.baseElement.querySelector('span.anticon-eye-invisible'),
15341534
).toBeFalsy();
1535-
expect(fn).toBeCalledWith(false);
1535+
expect(fn).toHaveBeenCalledWith(false);
15361536
});
15371537
html.unmount();
15381538
});
@@ -1710,7 +1710,7 @@ describe('Field', () => {
17101710
});
17111711

17121712
await waitFor(() => {
1713-
expect(change).toBeCalledWith('1.00000000000007');
1713+
expect(change).toHaveBeenCalledWith('1.00000000000007');
17141714
});
17151715
});
17161716

@@ -1919,7 +1919,7 @@ describe('Field', () => {
19191919
/>,
19201920
);
19211921
await waitFor(() => {
1922-
expect(requestFn).toBeCalledTimes(1);
1922+
expect(requestFn).toHaveBeenCalledTimes(1);
19231923
});
19241924

19251925
act(() => {
@@ -1929,7 +1929,7 @@ describe('Field', () => {
19291929
});
19301930

19311931
await waitFor(() => {
1932-
expect(requestFn).toBeCalledTimes(2);
1932+
expect(requestFn).toHaveBeenCalledTimes(2);
19331933
});
19341934
});
19351935

0 commit comments

Comments
 (0)