@@ -3,7 +3,7 @@ import { renderHook } from '@testing-library/react-hooks';
33import useList from '..' ;
44
55describe ( 'Test useList hook' , ( ) => {
6- it ( 'Should get initial data with default params' , ( ) => {
6+ it ( 'Should get initial data with default params' , async ( ) => {
77 const fetcher = jest . fn ( ) . mockResolvedValue ( {
88 total : 1 ,
99 data : [ { uuid : 1 } ] ,
@@ -12,12 +12,12 @@ describe('Test useList hook', () => {
1212 const { result } = renderHook ( ( ) => useList ( fetcher , { current : 1 , pageSize : 20 } ) ) ;
1313
1414 expect ( fetcher ) . toBeCalledTimes ( 1 ) ;
15- waitFor ( ( ) => {
15+ await waitFor ( ( ) => {
1616 expect ( result . current . data . length ) . toBe ( 1 ) ;
17- expect ( result . current . params ) . toBe (
18- expect . objectContaining ( { current : 1 , pageSize : 20 , total : 1 } )
19- ) ;
2017 } ) ;
18+ expect ( result . current . params ) . toEqual (
19+ expect . objectContaining ( { current : 1 , pageSize : 20 , total : 1 } )
20+ ) ;
2121 } ) ;
2222
2323 it ( 'Should get data after mutating' , ( ) => {
@@ -35,10 +35,9 @@ describe('Test useList hook', () => {
3535 result . current . mutate ( { search : 'test' } ) ;
3636 } ) ;
3737
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' } ) ) ;
4241 } ) ;
4342
4443 it ( 'Should support revalidate after mutating' , ( ) => {
@@ -56,9 +55,7 @@ describe('Test useList hook', () => {
5655 result . current . mutate ( { search : 'test' } , { revalidate : false } ) ;
5756 } ) ;
5857
59- waitFor ( ( ) => {
60- expect ( result . current . params ) . toBe ( expect . objectContaining ( { search : 'test' } ) ) ;
61- } ) ;
58+ expect ( result . current . params ) . toEqual ( expect . objectContaining ( { search : 'test' } ) ) ;
6259 } ) ;
6360
6461 it ( 'Should support get data with current params' , ( ) => {
@@ -76,8 +73,6 @@ describe('Test useList hook', () => {
7673 result . current . mutate ( ) ;
7774 } ) ;
7875
79- waitFor ( ( ) => {
80- expect ( fetcher ) . toBeCalledTimes ( 2 ) ;
81- } ) ;
76+ expect ( fetcher ) . toBeCalledTimes ( 2 ) ;
8277 } ) ;
8378} ) ;
0 commit comments