Open History to see the last commit
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})