@@ -3,7 +3,7 @@ import { renderHook } from '@testing-library/react-hooks';
3
3
import useList from '..' ;
4
4
5
5
describe ( 'Test useList hook' , ( ) => {
6
- it ( 'Should get initial data with default params' , ( ) => {
6
+ it ( 'Should get initial data with default params' , async ( ) => {
7
7
const fetcher = jest . fn ( ) . mockResolvedValue ( {
8
8
total : 1 ,
9
9
data : [ { uuid : 1 } ] ,
@@ -12,12 +12,12 @@ describe('Test useList hook', () => {
12
12
const { result } = renderHook ( ( ) => useList ( fetcher , { current : 1 , pageSize : 20 } ) ) ;
13
13
14
14
expect ( fetcher ) . toBeCalledTimes ( 1 ) ;
15
- waitFor ( ( ) => {
15
+ await waitFor ( ( ) => {
16
16
expect ( result . current . data . length ) . toBe ( 1 ) ;
17
- expect ( result . current . params ) . toBe (
18
- expect . objectContaining ( { current : 1 , pageSize : 20 , total : 1 } )
19
- ) ;
20
17
} ) ;
18
+ expect ( result . current . params ) . toEqual (
19
+ expect . objectContaining ( { current : 1 , pageSize : 20 , total : 1 } )
20
+ ) ;
21
21
} ) ;
22
22
23
23
it ( 'Should get data after mutating' , ( ) => {
@@ -35,10 +35,9 @@ describe('Test useList hook', () => {
35
35
result . current . mutate ( { search : 'test' } ) ;
36
36
} ) ;
37
37
38
- waitFor ( ( ) => {
39
- expect ( fetcher ) . toBeCalledTimes ( 2 ) ;
40
- expect ( result . current . params ) . toBe ( expect . objectContaining ( { search : 'test' } ) ) ;
41
- } ) ;
38
+ expect ( fetcher ) . toBeCalledTimes ( 2 ) ;
39
+ expect ( result . current . params ) . toEqual ( expect . objectContaining ( { search : 'test' } ) ) ;
40
+ expect ( fetcher . mock . calls [ 1 ] [ 0 ] ) . toEqual ( expect . objectContaining ( { search : 'test' } ) ) ;
42
41
} ) ;
43
42
44
43
it ( 'Should support revalidate after mutating' , ( ) => {
@@ -56,9 +55,7 @@ describe('Test useList hook', () => {
56
55
result . current . mutate ( { search : 'test' } , { revalidate : false } ) ;
57
56
} ) ;
58
57
59
- waitFor ( ( ) => {
60
- expect ( result . current . params ) . toBe ( expect . objectContaining ( { search : 'test' } ) ) ;
61
- } ) ;
58
+ expect ( result . current . params ) . toEqual ( expect . objectContaining ( { search : 'test' } ) ) ;
62
59
} ) ;
63
60
64
61
it ( 'Should support get data with current params' , ( ) => {
@@ -76,8 +73,6 @@ describe('Test useList hook', () => {
76
73
result . current . mutate ( ) ;
77
74
} ) ;
78
75
79
- waitFor ( ( ) => {
80
- expect ( fetcher ) . toBeCalledTimes ( 2 ) ;
81
- } ) ;
76
+ expect ( fetcher ) . toBeCalledTimes ( 2 ) ;
82
77
} ) ;
83
78
} ) ;
0 commit comments