Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

index.test.ts

31 lines866 Bytes

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', () => {
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', () => {
24 const unsubscribe = broadcastQueryClient({
25 queryClient,
26 broadcastChannel: 'test_channel',
27 })
28 unsubscribe()
29 expect(queryCache.hasListeners()).toBe(false)
30 })
31})