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