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
5 changes: 1 addition & 4 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ export default [
{
files: ['**/*.spec.ts*', '**/*.test.ts*', '**/*.test-d.ts*'],
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': 'warn',
},
rules: vitest.configs.recommended.rules,
settings: { vitest: { typecheck: true } },
},
]
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
QueryClient,
provideTanStackQuery,
} from '@tanstack/angular-query-experimental'
import { beforeEach, describe, expect, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { injectDevtoolsPanel } from '../inject-devtools-panel'

const mockDevtoolsPanelInstance = {
Expand Down
3 changes: 1 addition & 2 deletions packages/angular-query-devtools-experimental/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"noPropertyAccessFromIndexSignature": true,
"noFallthroughCasesInSwitch": true,
"useDefineForClassFields": false,
"target": "ES2022",
"types": ["vitest/globals"]
"target": "ES2022"
},
"include": ["src", "*.config.js", "*.config.ts", "package.json"],
"references": [
Expand Down
10 changes: 10 additions & 0 deletions packages/angular-query-experimental/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @ts-check

import pluginJsdoc from 'eslint-plugin-jsdoc'
import vitest from '@vitest/eslint-plugin'
import rootConfig from './root.eslint.config.js'

export default [
Expand Down Expand Up @@ -28,4 +29,13 @@ export default [
],
},
},
{
plugins: { vitest },
rules: {
'vitest/expect-expect': [
'error',
{ assertFunctionNames: ['expect', 'expectSignals'] },
],
},
},
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestBed } from '@angular/core/testing'
import { afterEach } from 'vitest'
import { afterEach, beforeEach, describe, expectTypeOf, test, vi } from 'vitest'
import { provideExperimentalZonelessChangeDetection } from '@angular/core'
import { QueryClient, injectInfiniteQuery, provideTanStackQuery } from '..'
import { infiniteFetcher } from './test-utils'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestBed } from '@angular/core/testing'
import { afterEach } from 'vitest'
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
import {
Injector,
provideExperimentalZonelessChangeDetection,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestBed } from '@angular/core/testing'
import { beforeEach, describe, expect } from 'vitest'
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
import {
Injector,
provideExperimentalZonelessChangeDetection,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeEach, describe } from 'vitest'
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
import { TestBed } from '@angular/core/testing'
import {
Injector,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expectTypeOf } from 'vitest'
import { describe, expectTypeOf, it } from 'vitest'
import { injectMutationState } from '..'
import type { MutationState, MutationStatus } from '..'

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 { describe, expect, test, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
import { By } from '@angular/platform-browser'
import {
QueryClient,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expectTypeOf } from 'vitest'
import { describe, expectTypeOf, test } from 'vitest'
import { injectMutation } from '..'
import { successMutator } from './test-utils'
import type { Signal } from '@angular/core'
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 { describe, expect, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
import { By } from '@angular/platform-browser'
import { QueryClient, injectMutation, provideTanStackQuery } from '..'
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expectTypeOf, it } from 'vitest'
import { describe, expectTypeOf, it, test } from 'vitest'
import { injectQuery, queryOptions } from '..'
import { simpleFetcher } from './test-utils'
import type { Signal } from '@angular/core'
Expand Down Expand Up @@ -108,11 +108,14 @@ describe('initialData', () => {
})

describe('structuralSharing', () => {
it('should restrict to same types', () => {
it('should be able to use structuralSharing with unknown types', () => {
// https://github.com/TanStack/query/issues/6525#issuecomment-1938411343
injectQuery(() => ({
queryKey: ['key'],
queryFn: () => 5,
structuralSharing: (_oldData, newData) => {
structuralSharing: (oldData, newData) => {
expectTypeOf(oldData).toBeUnknown()
expectTypeOf(newData).toBeUnknown()
return newData
},
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ import {
signal,
} from '@angular/core'
import { TestBed } from '@angular/core/testing'
import { afterEach, describe, expect, vi } from 'vitest'
import {
afterEach,
beforeEach,
describe,
expect,
expectTypeOf,
test,
vi,
} from 'vitest'
import { QueryCache, QueryClient, injectQuery, provideTanStackQuery } from '..'
import {
delayedFetcher,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
import { assertType, describe, expectTypeOf, test } from 'vitest'
import { mutationOptions } from '../mutation-options'

describe('mutationOptions', () => {
test('should not allow excess properties', () => {
return mutationOptions({
mutationFn: () => Promise.resolve(5),
mutationKey: ['key'],
// @ts-expect-error this is a good error, because onMutates does not exist!
onMutates: 1000,
})
assertType<Parameters<typeof mutationOptions>>([
{
mutationFn: () => Promise.resolve(5),
mutationKey: ['key'],
// @ts-expect-error this is a good error, because onMutates does not exist!
onMutates: 1000,
},
])
assertType<Parameters<typeof mutationOptions>>([
{
mutationFn: () => Promise.resolve(5),
mutationKey: ['key'],
// @ts-expect-error this is a good error, because onMutates does not exist!
onMutates: 1000,
},
])
})

test('should infer types for callbacks', () => {
return mutationOptions({
mutationOptions({
mutationFn: () => Promise.resolve(5),
mutationKey: ['key'],
onSuccess: (data) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, test, vi } from 'vitest'
import { afterEach, beforeEach, describe, expect, it, test, vi } from 'vitest'
import { QueryClient } from '@tanstack/query-core'
import { TestBed } from '@angular/core/testing'
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import { assertType, describe, expectTypeOf } from 'vitest'
import { assertType, describe, expectTypeOf, test } from 'vitest'
import { QueryClient, dataTagSymbol, injectQuery, queryOptions } from '..'
import type { Signal } from '@angular/core'

describe('queryOptions', () => {
test('should not allow excess properties', () => {
return queryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve(5),
// @ts-expect-error this is a good error, because stallTime does not exist!
stallTime: 1000,
})
expectTypeOf(queryOptions).parameter(0).not.toHaveProperty('stallTime')
})

test('should infer types for callbacks', () => {
return queryOptions({
queryOptions({
queryKey: ['key'],
queryFn: () => Promise.resolve(5),
staleTime: 1000,
Expand All @@ -24,7 +19,7 @@ describe('queryOptions', () => {
})

test('should allow undefined response in initialData', () => {
return (id: string | null) =>
const options = (id: string | null) =>
queryOptions({
queryKey: ['todo', id],
queryFn: () =>
Expand All @@ -40,6 +35,10 @@ describe('queryOptions', () => {
title: 'Initial Data',
},
})

expectTypeOf(options(null).initialData).returns.toEqualTypeOf<
{ id: string; title: string } | undefined
>()
})
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isSignal, signal } from '@angular/core'
import { describe } from 'vitest'
import { describe, expect, test } from 'vitest'
import { signalProxy } from '../signal-proxy'

describe('signalProxy', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { isSignal, untracked } from '@angular/core'
import { SIGNAL, signalSetFn } from '@angular/core/primitives/signals'
import { expect } from 'vitest'
import type { InputSignal, Signal } from '@angular/core'
import type { ComponentFixture } from '@angular/core/testing'

Expand Down
3 changes: 1 addition & 2 deletions packages/angular-query-experimental/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"noPropertyAccessFromIndexSignature": true,
"noFallthroughCasesInSwitch": true,
"useDefineForClassFields": false,
"target": "ES2022",
"types": ["vitest/globals"]
"target": "ES2022"
},
"include": ["src", "*.config.js", "*.config.ts", "package.json"],
"references": [{ "path": "../query-core" }, { "path": "../query-devtools" }]
Expand Down
3 changes: 1 addition & 2 deletions packages/angular-query-persist-client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"noPropertyAccessFromIndexSignature": true,
"noFallthroughCasesInSwitch": true,
"useDefineForClassFields": false,
"target": "ES2022",
"types": ["vitest/globals"]
"target": "ES2022"
},
"include": ["src", "*.config.js", "*.config.ts", "package.json"],
"references": [
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin-query/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default [
{
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
'vitest/expect-expect': [
'warn',
{
Expand Down
1 change: 1 addition & 0 deletions packages/query-codemods/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @ts-check

import vitest from '@vitest/eslint-plugin'
import rootConfig from './root.eslint.config.js'

export default [
Expand Down
22 changes: 17 additions & 5 deletions packages/query-core/src/__tests__/notifyManager.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import {
afterEach,
assertType,
beforeEach,
describe,
expect,
expectTypeOf,
it,
vi,
} from 'vitest'
import { createNotifyManager } from '../notifyManager'
import { sleep } from './utils'

Expand Down Expand Up @@ -81,10 +90,13 @@ describe('notifyManager', () => {
// now someFn expect to be called with args [a: string, b: number]
const someFn = notifyManagerTest.batchCalls(fn)

someFn('im happy', 4)

// @ts-expect-error
someFn('im not happy', false)
expectTypeOf(someFn).parameters.toEqualTypeOf<Parameters<typeof fn>>()
assertType<Parameters<typeof someFn>>(['im happy', 4])
assertType<Parameters<typeof someFn>>([
'im not happy',
// @ts-expect-error
false,
])
})

it('should use custom batch notify function', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/query-core/src/__tests__/query.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ describe('query', () => {
const key = queryKey()

const queryFn = vi
.fn()
.fn<() => Promise<string>>()
.mockImplementation(() => sleep(10).then(() => 'data'))

queryClient.prefetchQuery({
Expand Down
Loading
Loading