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

provide-tanstack-query.test.ts

41 lines1.2 KB

1import { TestBed } from '@angular/core/testing'
2import { describe, expect, test } from 'vitest'
3import {
4 InjectionToken,
5 provideExperimentalZonelessChangeDetection,
6} from '@angular/core'
7import { QueryClient } from '@tanstack/query-core'
8import { provideTanStackQuery } from '../providers'
9​
10describe('provideTanStackQuery', () => {
11 test('should provide a QueryClient instance directly', () => {
12 const queryClient = new QueryClient()
13​
14 TestBed.configureTestingModule({
15 providers: [
16 provideExperimentalZonelessChangeDetection(),
17 provideTanStackQuery(queryClient),
18 ],
19 })
20​
21 const providedQueryClient = TestBed.inject(QueryClient)
22 expect(providedQueryClient).toBe(queryClient)
23 })
24​
25 test('should provide a QueryClient instance using an InjectionToken', () => {
26 const queryClient = new QueryClient()
27 const CUSTOM_QUERY_CLIENT = new InjectionToken<QueryClient>('', {
28 factory: () => queryClient,
29 })
30​
31 TestBed.configureTestingModule({
32 providers: [
33 provideExperimentalZonelessChangeDetection(),
34 provideTanStackQuery(CUSTOM_QUERY_CLIENT),
35 ],
36 })
37​
38 const providedQueryClient = TestBed.inject(QueryClient)
39 expect(providedQueryClient).toBe(queryClient)
40 })
41})