-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathinject-infinite-query.test-d.ts
More file actions
43 lines (38 loc) · 1.24 KB
/
inject-infinite-query.test-d.ts
File metadata and controls
43 lines (38 loc) · 1.24 KB
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
33
34
35
36
37
38
39
40
41
42
43
import { TestBed } from '@angular/core/testing'
import { afterEach, beforeEach, describe, expectTypeOf, it, vi } from 'vitest'
import { provideZonelessChangeDetection } from '@angular/core'
import { queryKey, sleep } from '@tanstack/query-test-utils'
import { QueryClient, injectInfiniteQuery, provideTanStackQuery } from '..'
import type { InfiniteData } from '@tanstack/query-core'
describe('injectInfiniteQuery', () => {
let queryClient: QueryClient
beforeEach(() => {
queryClient = new QueryClient()
vi.useFakeTimers()
TestBed.configureTestingModule({
providers: [
provideZonelessChangeDetection(),
provideTanStackQuery(queryClient),
],
})
})
afterEach(() => {
vi.useRealTimers()
})
it('should narrow type after isSuccess', () => {
const key = queryKey()
const query = TestBed.runInInjectionContext(() => {
return injectInfiniteQuery(() => ({
queryKey: key,
queryFn: ({ pageParam }) =>
sleep(0).then(() => 'data on page ' + pageParam),
initialPageParam: 0,
getNextPageParam: () => 12,
}))
})
if (query.isSuccess()) {
const data = query.data()
expectTypeOf(data).toEqualTypeOf<InfiniteData<string, unknown>>()
}
})
})