Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe('infiniteQueryOptions', () => {
)
})

it('allow optional initialData function', () => {
it('should allow optional initialData function', () => {
const key = queryKey()
const initialData: { example: boolean } | undefined = { example: true }
const queryOptions = infiniteQueryOptions({
Expand All @@ -185,7 +185,7 @@ describe('infiniteQueryOptions', () => {
>()
})

it('allow optional initialData object', () => {
it('should allow optional initialData object', () => {
const key = queryKey()
const initialData: { example: boolean } | undefined = { example: true }
const queryOptions = infiniteQueryOptions({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('injectInfiniteQuery', () => {
})

describe('injection context', () => {
it('throws NG0203 with descriptive error outside injection context', () => {
it('should throw NG0203 with descriptive error outside injection context', () => {
const key = queryKey()
expect(() => {
injectInfiniteQuery(() => ({
Expand All @@ -77,7 +77,7 @@ describe('injectInfiniteQuery', () => {
}).toThrow(/NG0203(.*?)injectInfiniteQuery/)
})

it('can be used outside injection context when passing an injector', () => {
it('should be usable outside injection context when passing an injector', () => {
const key = queryKey()
const query = injectInfiniteQuery(
() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('injectIsFetching', () => {
vi.useRealTimers()
})

it('Returns number of fetching queries', async () => {
it('should return the number of fetching queries', async () => {
const key = queryKey()
const isFetching = TestBed.runInInjectionContext(() => {
injectQuery(() => ({
Expand All @@ -46,13 +46,13 @@ describe('injectIsFetching', () => {
})

describe('injection context', () => {
it('throws NG0203 with descriptive error outside injection context', () => {
it('should throw NG0203 with descriptive error outside injection context', () => {
expect(() => {
injectIsFetching()
}).toThrow(/NG0203(.*?)injectIsFetching/)
})

it('can be used outside injection context when passing an injector', () => {
it('should be usable outside injection context when passing an injector', () => {
expect(
injectIsFetching(undefined, {
injector: TestBed.inject(Injector),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ describe('injectIsMutating', () => {
})

describe('injection context', () => {
it('throws NG0203 with descriptive error outside injection context', () => {
it('should throw NG0203 with descriptive error outside injection context', () => {
expect(() => {
injectIsMutating()
}).toThrow(/NG0203(.*?)injectIsMutating/)
})

it('can be used outside injection context when passing an injector', () => {
it('should be usable outside injection context when passing an injector', () => {
expect(
injectIsMutating(undefined, {
injector: TestBed.inject(Injector),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestBed } from '@angular/core/testing'
import { describe, expect, it } from 'vitest'
import { beforeEach, describe, expect, it } from 'vitest'
import { Injector, provideZonelessChangeDetection, signal } from '@angular/core'
import {
QueryClient,
Expand All @@ -11,33 +11,29 @@ import {
describe('injectIsRestoring', () => {
let queryClient: QueryClient

it('returns false by default when provideIsRestoring is not used', () => {
beforeEach(() => {
queryClient = new QueryClient()

TestBed.configureTestingModule({
providers: [
provideZonelessChangeDetection(),
provideTanStackQuery(queryClient),
],
})
})

it('should return false by default when provideIsRestoring is not used', () => {
const isRestoring = TestBed.runInInjectionContext(() => {
return injectIsRestoring()
})

expect(isRestoring()).toBe(false)
})

it('returns provided signal value when provideIsRestoring is used', () => {
queryClient = new QueryClient()
it('should return the provided signal value when provideIsRestoring is used', () => {
const restoringSignal = signal(true)

TestBed.configureTestingModule({
providers: [
provideZonelessChangeDetection(),
provideTanStackQuery(queryClient),
provideIsRestoring(restoringSignal.asReadonly()),
],
providers: [provideIsRestoring(restoringSignal.asReadonly())],
})

const isRestoring = TestBed.runInInjectionContext(() => {
Expand All @@ -47,24 +43,15 @@ describe('injectIsRestoring', () => {
expect(isRestoring()).toBe(true)
})

it('can be used outside injection context when passing an injector', () => {
queryClient = new QueryClient()

TestBed.configureTestingModule({
providers: [
provideZonelessChangeDetection(),
provideTanStackQuery(queryClient),
],
})

it('should be usable outside injection context when passing an injector', () => {
const isRestoring = injectIsRestoring({
injector: TestBed.inject(Injector),
})

expect(isRestoring()).toBe(false)
})

it('throws NG0203 with descriptive error outside injection context', () => {
it('should throw NG0203 with descriptive error outside injection context', () => {
expect(() => {
injectIsRestoring()
}).toThrow(/NG0203(.*?)injectIsRestoring/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('injectMutationState', () => {
expect(mutationState()).toEqual([variables])
})

it('reactive options should update injectMutationState', () => {
it('should update injectMutationState when reactive options change', () => {
const mutationKey1 = queryKey()
const mutationKey2 = queryKey()
const variables1 = 'foo123'
Expand Down Expand Up @@ -179,13 +179,13 @@ describe('injectMutationState', () => {
})

describe('injection context', () => {
it('throws NG0203 with descriptive error outside injection context', () => {
it('should throw NG0203 with descriptive error outside injection context', () => {
expect(() => {
injectMutationState()
}).toThrow(/NG0203(.*?)injectMutationState/)
})

it('can be used outside injection context when passing an injector', () => {
it('should be usable outside injection context when passing an injector', () => {
const injector = TestBed.inject(Injector)
expect(
injectMutationState(undefined, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('injectMutation', () => {
})
})

it('reactive options should update mutation', () => {
it('should update mutation when reactive options change', () => {
const mutationCache = queryClient.getMutationCache()
// Signal will be updated before the mutation is called
// this test confirms that the mutation uses the updated value
Expand Down Expand Up @@ -473,7 +473,7 @@ describe('injectMutation', () => {
})

describe('injection context', () => {
it('throws NG0203 with descriptive error outside injection context', () => {
it('should throw NG0203 with descriptive error outside injection context', () => {
const key = queryKey()
expect(() => {
injectMutation(() => ({
Expand All @@ -483,7 +483,7 @@ describe('injectMutation', () => {
}).toThrow(/NG0203(.*?)injectMutation/)
})

it('can be used outside injection context when passing an injector', () => {
it('should be usable outside injection context when passing an injector', () => {
const key = queryKey()
expect(() => {
injectMutation(
Expand Down Expand Up @@ -536,14 +536,6 @@ describe('injectMutation', () => {
})

it('should handle synchronous mutation with retry', async () => {
TestBed.resetTestingModule()
TestBed.configureTestingModule({
providers: [
provideZonelessChangeDetection(),
provideTanStackQuery(queryClient),
],
})

const app = TestBed.inject(ApplicationRef)
let attemptCount = 0

Expand Down Expand Up @@ -586,14 +578,6 @@ describe('injectMutation', () => {
})

it('should handle multiple synchronous mutations on same key', async () => {
TestBed.resetTestingModule()
TestBed.configureTestingModule({
providers: [
provideZonelessChangeDetection(),
provideTanStackQuery(queryClient),
],
})

const app = TestBed.inject(ApplicationRef)
let callCount = 0

Expand Down Expand Up @@ -640,14 +624,6 @@ describe('injectMutation', () => {
})

it('should handle synchronous mutation with optimistic updates', async () => {
TestBed.resetTestingModule()
TestBed.configureTestingModule({
providers: [
provideZonelessChangeDetection(),
provideTanStackQuery(queryClient),
],
})

const app = TestBed.inject(ApplicationRef)
const testQueryKey = queryKey()
let onMutateCalled = false
Expand Down Expand Up @@ -692,14 +668,6 @@ describe('injectMutation', () => {
})

it('should handle synchronous mutation cancellation', async () => {
TestBed.resetTestingModule()
TestBed.configureTestingModule({
providers: [
provideZonelessChangeDetection(),
provideTanStackQuery(queryClient),
],
})

const app = TestBed.inject(ApplicationRef)

const key = queryKey()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ import { queryKey, sleep } from '@tanstack/query-test-utils'
import { QueryClient, provideIsRestoring, provideTanStackQuery } from '..'
import { injectQueries } from '../inject-queries'

let queryClient: QueryClient

beforeEach(() => {
vi.useFakeTimers()
queryClient = new QueryClient()
TestBed.configureTestingModule({
providers: [
provideZonelessChangeDetection(),
provideTanStackQuery(queryClient),
],
describe('injectQueries', () => {
let queryClient: QueryClient

beforeEach(() => {
vi.useFakeTimers()
queryClient = new QueryClient()
TestBed.configureTestingModule({
providers: [
provideZonelessChangeDetection(),
provideTanStackQuery(queryClient),
],
})
})
})

afterEach(() => {
vi.useRealTimers()
})
afterEach(() => {
vi.useRealTimers()
})

describe('injectQueries', () => {
it('should return the correct states', async () => {
const key1 = queryKey()
const key2 = queryKey()
Expand Down Expand Up @@ -143,13 +143,8 @@ describe('injectQueries', () => {
const queryFn1 = vi.fn().mockImplementation(() => sleep(10).then(() => 1))
const queryFn2 = vi.fn().mockImplementation(() => sleep(10).then(() => 2))

TestBed.resetTestingModule()
TestBed.configureTestingModule({
providers: [
provideZonelessChangeDetection(),
provideTanStackQuery(queryClient),
provideIsRestoring(signal(true).asReadonly()),
],
providers: [provideIsRestoring(signal(true).asReadonly())],
})

const queries = TestBed.runInInjectionContext(() =>
Expand Down
Loading
Loading