11import { QueryClient } from '@tanstack/query-core'
22import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest'
3- import { queryKey } from '@tanstack/query-test-utils'
3+ import { queryKey , sleep } from '@tanstack/query-test-utils'
44import { broadcastQueryClient } from '..'
55import type { BroadcastErrorEvent } from '..'
66import type { QueryCache } from '@tanstack/query-core'
@@ -83,7 +83,7 @@ describe('broadcastQueryClient', () => {
8383
8484 queryClient . setQueryData ( key , { value : 1 } )
8585
86- await new Promise ( ( r ) => setTimeout ( r , 0 ) )
86+ await sleep ( 0 )
8787
8888 expect ( onBroadcastError ) . toHaveBeenCalledWith (
8989 cloneError ,
@@ -119,7 +119,7 @@ describe('broadcastQueryClient', () => {
119119
120120 queryClient . setQueryData ( key , { value : 1 } )
121121
122- await new Promise ( ( r ) => setTimeout ( r , 0 ) )
122+ await sleep ( 0 )
123123
124124 expect ( warnSpy ) . toHaveBeenCalledWith (
125125 expect . stringContaining ( 'onBroadcastError threw while handling' ) ,
@@ -154,7 +154,7 @@ describe('broadcastQueryClient', () => {
154154
155155 queryClient . setQueryData ( key , { value : 1 } )
156156
157- await new Promise ( ( r ) => setTimeout ( r , 10 ) )
157+ await sleep ( 10 )
158158
159159 expect ( onBroadcastError ) . toHaveBeenCalledWith (
160160 cloneError ,
@@ -188,7 +188,7 @@ describe('broadcastQueryClient', () => {
188188
189189 queryClient . setQueryData ( key , { value : 1 } )
190190
191- await new Promise ( ( r ) => setTimeout ( r , 10 ) )
191+ await sleep ( 10 )
192192
193193 expect ( warnSpy ) . toHaveBeenCalledWith (
194194 expect . stringContaining ( 'onBroadcastError threw while handling' ) ,
@@ -213,7 +213,7 @@ describe('broadcastQueryClient', () => {
213213
214214 queryClient . setQueryData ( key , { value : 1 } )
215215
216- await new Promise ( ( r ) => setTimeout ( r , 0 ) )
216+ await sleep ( 0 )
217217 expect ( onBroadcastError ) . toHaveBeenCalledWith (
218218 cloneError ,
219219 expect . objectContaining < BroadcastErrorEvent > ( {
@@ -240,7 +240,7 @@ describe('broadcastQueryClient', () => {
240240
241241 queryClient . setQueryData ( key , { value : 1 } )
242242
243- await new Promise ( ( r ) => setTimeout ( r , 0 ) )
243+ await sleep ( 0 )
244244 expect ( warnSpy ) . toHaveBeenCalledWith (
245245 expect . stringContaining ( 'cross-tab sync for this query was skipped' ) ,
246246 cloneError ,
@@ -266,7 +266,7 @@ describe('broadcastQueryClient', () => {
266266
267267 queryClient . setQueryData ( key , { value : 1 } )
268268
269- await new Promise ( ( r ) => setTimeout ( r , 0 ) )
269+ await sleep ( 0 )
270270 expect ( warnSpy ) . not . toHaveBeenCalled ( )
271271 } finally {
272272 warnSpy . mockRestore ( )
0 commit comments