Open History to see the last commit
1import { QueryClient } from '@tanstack/query-core'
2import { beforeEach, describe, expect, it } from 'vitest'
3import { broadcastQueryClient } from '..'
4import type { QueryCache } from '@tanstack/query-core'
5β
6describe('broadcastQueryClient', () => {
7 let queryClient: QueryClient
8 let queryCache: QueryCache
9β
10 beforeEach(() => {
11 queryClient = new QueryClient()
12 queryCache = queryClient.getQueryCache()
13 })
14β
15 it('should subscribe to the query cache', async () => {
16 broadcastQueryClient({
17 queryClient,
18 broadcastChannel: 'test_channel',
19 })
20 expect(queryCache.hasListeners()).toBe(true)
21 })
22β
23 it('should not have any listeners after cleanup', async () => {
24 const unsubscribe = broadcastQueryClient({
25 queryClient,
26 broadcastChannel: 'test_channel',
27 })
28 unsubscribe()
29 expect(queryCache.hasListeners()).toBe(false)
30 })
31})