@@ -71,6 +71,39 @@ describe.sequential('useArbQueryParams debouncing', () => {
7171 } )
7272 } )
7373
74+ it ( 'should flush pending updates when receiving a call with debounce: false' , async ( ) => {
75+ const { result } = renderHook ( ( ) => useArbQueryParams ( ) , {
76+ wrapper : TestWrapper
77+ } )
78+
79+ await act ( async ( ) => {
80+ const [ , setQueryParams ] = result . current
81+ setQueryParams ( { amount : '10.5' } , { debounce : true } )
82+ setQueryParams ( { sourceChain : ChainId . ArbitrumOne } , { debounce : true } )
83+ setQueryParams (
84+ { destinationChain : ChainId . Ethereum } ,
85+ { debounce : false }
86+ )
87+ setQueryParams (
88+ { token : '0xaf88d065e77c8cc2239327c5edb3a432268e5831' } ,
89+ { debounce : true }
90+ )
91+ vi . runOnlyPendingTimers ( )
92+ } )
93+
94+ expect ( mockSetQueryParams ) . toHaveBeenCalledTimes ( 2 )
95+ // The first 2 debounced updates are merged with the first non-debounced update
96+ expect ( mockSetQueryParams ) . toHaveBeenNthCalledWith ( 1 , {
97+ amount : '10.5' ,
98+ sourceChain : ChainId . ArbitrumOne ,
99+ destinationChain : ChainId . Ethereum
100+ } )
101+
102+ expect ( mockSetQueryParams ) . toHaveBeenNthCalledWith ( 2 , {
103+ token : '0xaf88d065e77c8cc2239327c5edb3a432268e5831'
104+ } )
105+ } )
106+
74107 it ( 'should not be batched with debounce: false' , async ( ) => {
75108 const { result } = renderHook ( ( ) => useArbQueryParams ( ) , {
76109 wrapper : TestWrapper
@@ -86,16 +119,16 @@ describe.sequential('useArbQueryParams debouncing', () => {
86119 } )
87120
88121 expect ( mockSetQueryParams ) . toHaveBeenCalledTimes ( 4 )
89- expect ( mockSetQueryParams ) . toHaveBeenCalledWith ( {
122+ expect ( mockSetQueryParams ) . toHaveBeenNthCalledWith ( 1 , {
90123 amount : '10.5'
91124 } )
92- expect ( mockSetQueryParams ) . toHaveBeenCalledWith ( {
125+ expect ( mockSetQueryParams ) . toHaveBeenNthCalledWith ( 2 , {
93126 sourceChain : ChainId . ArbitrumOne
94127 } )
95- expect ( mockSetQueryParams ) . toHaveBeenCalledWith ( {
128+ expect ( mockSetQueryParams ) . toHaveBeenNthCalledWith ( 3 , {
96129 destinationChain : ChainId . Ethereum
97130 } )
98- expect ( mockSetQueryParams ) . toHaveBeenCalledWith ( {
131+ expect ( mockSetQueryParams ) . toHaveBeenNthCalledWith ( 4 , {
99132 token : '0xaf88d065e77c8cc2239327c5edb3a432268e5831'
100133 } )
101134 } )
0 commit comments