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

inject-infinite-query.test-d.ts

41 lines1.1 KB

1import { TestBed } from '@angular/core/testing'
2import { afterEach } from 'vitest'
3import { provideExperimentalZonelessChangeDetection } from '@angular/core'
4import { QueryClient, injectInfiniteQuery, provideTanStackQuery } from '..'
5import { infiniteFetcher } from './test-utils'
6import type { InfiniteData } from '@tanstack/query-core'
7​
8describe('injectInfiniteQuery', () => {
9 let queryClient: QueryClient
10​
11 beforeEach(() => {
12 queryClient = new QueryClient()
13 vi.useFakeTimers()
14 TestBed.configureTestingModule({
15 providers: [
16 provideExperimentalZonelessChangeDetection(),
17 provideTanStackQuery(queryClient),
18 ],
19 })
20 })
21​
22 afterEach(() => {
23 vi.useRealTimers()
24 })
25​
26 test('should narrow type after isSuccess', async () => {
27 const query = TestBed.runInInjectionContext(() => {
28 return injectInfiniteQuery(() => ({
29 queryKey: ['infiniteQuery'],
30 queryFn: infiniteFetcher,
31 initialPageParam: 0,
32 getNextPageParam: () => 12,
33 }))
34 })
35​
36 if (query.isSuccess()) {
37 const data = query.data()
38 expectTypeOf(data).toEqualTypeOf<InfiniteData<string, unknown>>()
39 }
40 })
41})