Open History to see the last commit
1import { describe, expectTypeOf, it } from 'vitest'
2import {
3 QueryClient,
4 provideTanStackQuery,
5 withHydrationKey,
6 withNoQueryHydration,
7} from '..'
8import type { QueryFeature } from '..'
9import type * as PublicApi from '..'
10import type * as InternalApi from '../internal'
11
12describe('provideTanStackQuery', () => {
13 it('keeps integration helpers out of the public entry point', () => {
14 type InternalHelpers =
15 | 'queryFeature'
16 | 'getQueryFeatureProviders'
17 | 'provideIsRestoring'
18 expectTypeOf<Extract<keyof typeof PublicApi, InternalHelpers>>().toBeNever()
19 expectTypeOf<
20 Extract<keyof typeof InternalApi, InternalHelpers>
21 >().toEqualTypeOf<InternalHelpers>()
22 })
23
24 it('accepts built-in opaque query features', () => {
25 expectTypeOf(withHydrationKey('cache')).toEqualTypeOf<QueryFeature>()
26 expectTypeOf(withNoQueryHydration()).toEqualTypeOf<QueryFeature>()
27
28 provideTanStackQuery(
29 () => new QueryClient(),
30 withHydrationKey('cache'),
31 withNoQueryHydration(),
32 )
33 })
34
35 it('rejects structurally fabricated features', () => {
36 expectTypeOf(withHydrationKey('cache')).toEqualTypeOf<QueryFeature>()
37
38 provideTanStackQuery(
39 () => new QueryClient(),
40 // @ts-expect-error QueryFeature values can only be created by package features
41 { ɵkind: 'Hydration', ɵproviders: {} },
42 )
43 })
44})