Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ export default [
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/consistent-test-it': [
'error',
{ fn: 'it', withinDescribe: 'it' },
],
'vitest/no-standalone-expect': [
'error',
{
additionalTestBlockFunctions: ['testIf'],
additionalTestBlockFunctions: ['itIf'],
},
],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertType, describe, expectTypeOf, it, test } from 'vitest'
import { assertType, describe, expectTypeOf, it } from 'vitest'
import { queryKey } from '@tanstack/query-test-utils'
import { QueryClient, dataTagSymbol } from '@tanstack/query-core'
import { infiniteQueryOptions } from '../infinite-query-options'
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('infiniteQueryOptions', () => {
>()
})

test('should not be allowed to be passed to non-infinite query functions', () => {
it('should not be allowed to be passed to non-infinite query functions', () => {
const key = queryKey()
const queryClient = new QueryClient()
const options = infiniteQueryOptions({
Expand All @@ -166,7 +166,7 @@ describe('infiniteQueryOptions', () => {
)
})

test('allow optional initialData function', () => {
it('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', () => {
>()
})

test('allow optional initialData object', () => {
it('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
@@ -1,5 +1,5 @@
import { TestBed } from '@angular/core/testing'
import { afterEach, beforeEach, describe, expectTypeOf, test, vi } from 'vitest'
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 '..'
Expand All @@ -23,7 +23,7 @@ describe('injectInfiniteQuery', () => {
vi.useRealTimers()
})

test('should narrow type after isSuccess', () => {
it('should narrow type after isSuccess', () => {
const key = queryKey()
const query = TestBed.runInInjectionContext(() => {
return injectInfiniteQuery(() => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestBed } from '@angular/core/testing'
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { Injector, provideZonelessChangeDetection } from '@angular/core'
import { queryKey, sleep } from '@tanstack/query-test-utils'
import { QueryClient, injectInfiniteQuery, provideTanStackQuery } from '..'
Expand All @@ -23,7 +23,7 @@ describe('injectInfiniteQuery', () => {
vi.useRealTimers()
})

test('should properly execute infinite query', async () => {
it('should properly execute infinite query', async () => {
const key = queryKey()
const query = TestBed.runInInjectionContext(() => {
return injectInfiniteQuery(() => ({
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('injectInfiniteQuery', () => {
})

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

test('can be used outside injection context when passing an injector', () => {
it('can be used 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
@@ -1,5 +1,5 @@
import { TestBed } from '@angular/core/testing'
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { Injector, provideZonelessChangeDetection } from '@angular/core'
import { queryKey, sleep } from '@tanstack/query-test-utils'
import {
Expand Down Expand Up @@ -28,7 +28,7 @@ describe('injectIsFetching', () => {
vi.useRealTimers()
})

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

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

test('can be used outside injection context when passing an injector', () => {
it('can be used 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
@@ -1,4 +1,4 @@
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { TestBed } from '@angular/core/testing'
import { Injector, provideZonelessChangeDetection } from '@angular/core'
import { queryKey, sleep } from '@tanstack/query-test-utils'
Expand Down Expand Up @@ -28,7 +28,7 @@ describe('injectIsMutating', () => {
vi.useRealTimers()
})

test('should properly return isMutating state', async () => {
it('should properly return isMutating state', async () => {
const key = queryKey()
const [mutation, isMutating] = TestBed.runInInjectionContext(() => [
injectMutation(() => ({
Expand All @@ -52,13 +52,13 @@ describe('injectIsMutating', () => {
})

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

test('can be used outside injection context when passing an injector', () => {
it('can be used 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, test } from 'vitest'
import { describe, expect, it } from 'vitest'
import { Injector, provideZonelessChangeDetection, signal } from '@angular/core'
import {
QueryClient,
Expand All @@ -11,7 +11,7 @@ import {
describe('injectIsRestoring', () => {
let queryClient: QueryClient

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

TestBed.configureTestingModule({
Expand All @@ -28,7 +28,7 @@ describe('injectIsRestoring', () => {
expect(isRestoring()).toBe(false)
})

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

Expand All @@ -47,7 +47,7 @@ describe('injectIsRestoring', () => {
expect(isRestoring()).toBe(true)
})

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

TestBed.configureTestingModule({
Expand All @@ -64,7 +64,7 @@ describe('injectIsRestoring', () => {
expect(isRestoring()).toBe(false)
})

test('throws NG0203 with descriptive error outside injection context', () => {
it('throws 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 @@ -6,7 +6,7 @@ import {
signal,
} from '@angular/core'
import { TestBed } from '@angular/core/testing'
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { By } from '@angular/platform-browser'
import { queryKey, sleep } from '@tanstack/query-test-utils'
import {
Expand Down Expand Up @@ -36,7 +36,7 @@ describe('injectMutationState', () => {
})

describe('injectMutationState', () => {
test('should return variables after calling mutate 1', () => {
it('should return variables after calling mutate 1', () => {
const mutationKey = queryKey()
const variables = 'foo123'

Expand All @@ -59,7 +59,7 @@ describe('injectMutationState', () => {
expect(mutationState()).toEqual([variables])
})

test('reactive options should update injectMutationState', () => {
it('reactive options should update injectMutationState', () => {
const mutationKey1 = queryKey()
const mutationKey2 = queryKey()
const variables1 = 'foo123'
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('injectMutationState', () => {
expect(mutationState()).toEqual([variables2])
})

test('should return variables after calling mutate 2', () => {
it('should return variables after calling mutate 2', () => {
queryClient.clear()
const mutationKey = queryKey()
const variables = 'bar234'
Expand All @@ -117,7 +117,7 @@ describe('injectMutationState', () => {
expect(mutationState()[0]?.variables).toEqual(variables)
})

test('should support required signal inputs', async () => {
it('should support required signal inputs', async () => {
queryClient.clear()
const fakeName = 'name1'
const mutationKey1 = ['fake', fakeName]
Expand Down Expand Up @@ -179,13 +179,13 @@ describe('injectMutationState', () => {
})

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

test('can be used outside injection context when passing an injector', () => {
it('can be used 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
@@ -1,19 +1,19 @@
import { describe, expectTypeOf, test } from 'vitest'
import { describe, expectTypeOf, it } from 'vitest'
import { sleep } from '@tanstack/query-test-utils'
import { injectMutation } from '..'
import type { Signal } from '@angular/core'

describe('injectMutation', () => {
describe('Discriminated union return type', () => {
test('data should be possibly undefined by default', () => {
it('data should be possibly undefined by default', () => {
const mutation = injectMutation(() => ({
mutationFn: () => sleep(0).then(() => 'string'),
}))

expectTypeOf(mutation.data).toEqualTypeOf<Signal<string | undefined>>()
})

test('data should be defined when mutation is success', () => {
it('data should be defined when mutation is success', () => {
const mutation = injectMutation(() => ({
mutationFn: () => sleep(0).then(() => 'string'),
}))
Expand All @@ -23,7 +23,7 @@ describe('injectMutation', () => {
}
})

test('error should be null when mutation is success', () => {
it('error should be null when mutation is success', () => {
const mutation = injectMutation(() => ({
mutationFn: () => sleep(0).then(() => 'string'),
}))
Expand All @@ -33,7 +33,7 @@ describe('injectMutation', () => {
}
})

test('data should be undefined when mutation is pending', () => {
it('data should be undefined when mutation is pending', () => {
const mutation = injectMutation(() => ({
mutationFn: () => sleep(0).then(() => 'string'),
}))
Expand All @@ -43,7 +43,7 @@ describe('injectMutation', () => {
}
})

test('error should be defined when mutation is error', () => {
it('error should be defined when mutation is error', () => {
const mutation = injectMutation(() => ({
mutationFn: () => sleep(0).then(() => 'string'),
}))
Expand All @@ -53,7 +53,7 @@ describe('injectMutation', () => {
}
})

test('should narrow variables', () => {
it('should narrow variables', () => {
const mutation = injectMutation(() => ({
mutationFn: (_variables: string) => sleep(0).then(() => 'string'),
}))
Expand Down
Loading
Loading