Skip to content

Commit 06ac87e

Browse files
authored
ci(angular-query, query-core): update vitest/expect-expect rule as error (#9109)
1 parent 0943575 commit 06ac87e

27 files changed

+96
-124
lines changed

packages/angular-query-devtools-experimental/src/__tests__/inject-devtools-panel.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
QueryClient,
99
provideTanStackQuery,
1010
} from '@tanstack/angular-query-experimental'
11-
import { beforeEach, describe, expect, vi } from 'vitest'
11+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
1212
import { injectDevtoolsPanel } from '../inject-devtools-panel'
1313

1414
const mockDevtoolsPanelInstance = {

packages/angular-query-devtools-experimental/tsconfig.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"noPropertyAccessFromIndexSignature": true,
99
"noFallthroughCasesInSwitch": true,
1010
"useDefineForClassFields": false,
11-
"target": "ES2022",
12-
"types": ["vitest/globals"]
11+
"target": "ES2022"
1312
},
1413
"include": ["src", "*.config.js", "*.config.ts", "package.json"],
1514
"references": [

packages/angular-query-experimental/src/__tests__/inject-infinite-query.test-d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TestBed } from '@angular/core/testing'
2-
import { afterEach } from 'vitest'
2+
import { afterEach, beforeEach, describe, expectTypeOf, test, vi } from 'vitest'
33
import { provideExperimentalZonelessChangeDetection } from '@angular/core'
44
import { QueryClient, injectInfiniteQuery, provideTanStackQuery } from '..'
55
import { infiniteFetcher } from './test-utils'

packages/angular-query-experimental/src/__tests__/inject-infinite-query.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TestBed } from '@angular/core/testing'
2-
import { afterEach } from 'vitest'
2+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
33
import {
44
Injector,
55
provideExperimentalZonelessChangeDetection,

packages/angular-query-experimental/src/__tests__/inject-is-fetching.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TestBed } from '@angular/core/testing'
2-
import { beforeEach, describe, expect } from 'vitest'
2+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
33
import {
44
Injector,
55
provideExperimentalZonelessChangeDetection,

packages/angular-query-experimental/src/__tests__/inject-is-mutating.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, describe } from 'vitest'
1+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
22
import { TestBed } from '@angular/core/testing'
33
import {
44
Injector,

packages/angular-query-experimental/src/__tests__/inject-mutation-state.test-d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expectTypeOf } from 'vitest'
1+
import { describe, expectTypeOf, it } from 'vitest'
22
import { injectMutationState } from '..'
33
import type { MutationState, MutationStatus } from '..'
44

packages/angular-query-experimental/src/__tests__/inject-mutation-state.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
signal,
77
} from '@angular/core'
88
import { TestBed } from '@angular/core/testing'
9-
import { describe, expect, test, vi } from 'vitest'
9+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
1010
import { By } from '@angular/platform-browser'
1111
import {
1212
QueryClient,

packages/angular-query-experimental/src/__tests__/inject-mutation.test-d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expectTypeOf } from 'vitest'
1+
import { describe, expectTypeOf, test } from 'vitest'
22
import { injectMutation } from '..'
33
import { successMutator } from './test-utils'
44
import type { Signal } from '@angular/core'

packages/angular-query-experimental/src/__tests__/inject-mutation.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
signal,
77
} from '@angular/core'
88
import { TestBed } from '@angular/core/testing'
9-
import { describe, expect, vi } from 'vitest'
9+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
1010
import { By } from '@angular/platform-browser'
1111
import { QueryClient, injectMutation, provideTanStackQuery } from '..'
1212
import {

packages/angular-query-experimental/src/__tests__/inject-query.test-d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expectTypeOf, it } from 'vitest'
1+
import { describe, expectTypeOf, it, test } from 'vitest'
22
import { injectQuery, queryOptions } from '..'
33
import { simpleFetcher } from './test-utils'
44
import type { Signal } from '@angular/core'

packages/angular-query-experimental/src/__tests__/inject-query.test.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ import {
88
signal,
99
} from '@angular/core'
1010
import { TestBed } from '@angular/core/testing'
11-
import { afterEach, describe, expect, vi } from 'vitest'
11+
import {
12+
afterEach,
13+
beforeEach,
14+
describe,
15+
expect,
16+
expectTypeOf,
17+
test,
18+
vi,
19+
} from 'vitest'
1220
import { QueryCache, QueryClient, injectQuery, provideTanStackQuery } from '..'
1321
import {
1422
delayedFetcher,

packages/angular-query-experimental/src/__tests__/mutation-options.test-d.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1+
import { assertType, describe, expectTypeOf, test } from 'vitest'
12
import { mutationOptions } from '../mutation-options'
23

34
describe('mutationOptions', () => {
45
test('should not allow excess properties', () => {
5-
expectTypeOf(mutationOptions).parameter(0).not.toHaveProperty('onMutates')
6+
assertType<Parameters<typeof mutationOptions>>([
7+
{
8+
mutationFn: () => Promise.resolve(5),
9+
mutationKey: ['key'],
10+
// @ts-expect-error this is a good error, because onMutates does not exist!
11+
onMutates: 1000,
12+
},
13+
])
14+
assertType<Parameters<typeof mutationOptions>>([
15+
{
16+
mutationFn: () => Promise.resolve(5),
17+
mutationKey: ['key'],
18+
// @ts-expect-error this is a good error, because onMutates does not exist!
19+
onMutates: 1000,
20+
},
21+
])
622
})
723

824
test('should infer types for callbacks', () => {
9-
return mutationOptions({
25+
mutationOptions({
1026
mutationFn: () => Promise.resolve(5),
1127
mutationKey: ['key'],
1228
onSuccess: (data) => {

packages/angular-query-experimental/src/__tests__/providers.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, describe, expect, test, vi } from 'vitest'
1+
import { afterEach, beforeEach, describe, expect, it, test, vi } from 'vitest'
22
import { QueryClient } from '@tanstack/query-core'
33
import { TestBed } from '@angular/core/testing'
44
import {

packages/angular-query-experimental/src/__tests__/query-options.test-d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertType, describe, expectTypeOf } from 'vitest'
1+
import { assertType, describe, expectTypeOf, test } from 'vitest'
22
import { QueryClient, dataTagSymbol, injectQuery, queryOptions } from '..'
33
import type { Signal } from '@angular/core'
44

packages/angular-query-experimental/src/__tests__/signal-proxy.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { isSignal, signal } from '@angular/core'
2-
import { describe } from 'vitest'
2+
import { describe, expect, test } from 'vitest'
33
import { signalProxy } from '../signal-proxy'
44

55
describe('signalProxy', () => {

packages/angular-query-experimental/src/__tests__/test-utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { isSignal, untracked } from '@angular/core'
22
import { SIGNAL, signalSetFn } from '@angular/core/primitives/signals'
3+
import { expect } from 'vitest'
34
import type { InputSignal, Signal } from '@angular/core'
45
import type { ComponentFixture } from '@angular/core/testing'
56

packages/angular-query-experimental/tsconfig.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"noPropertyAccessFromIndexSignature": true,
99
"noFallthroughCasesInSwitch": true,
1010
"useDefineForClassFields": false,
11-
"target": "ES2022",
12-
"types": ["vitest/globals"]
11+
"target": "ES2022"
1312
},
1413
"include": ["src", "*.config.js", "*.config.ts", "package.json"],
1514
"references": [{ "path": "../query-core" }, { "path": "../query-devtools" }]

packages/angular-query-persist-client/tsconfig.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
"noPropertyAccessFromIndexSignature": true,
1010
"noFallthroughCasesInSwitch": true,
1111
"useDefineForClassFields": false,
12-
"target": "ES2022",
13-
"types": ["vitest/globals"]
12+
"target": "ES2022"
1413
},
1514
"include": ["src", "*.config.js", "*.config.ts", "package.json"],
1615
"references": [
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
// @ts-check
22

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

6-
export default [
7-
...rootConfig,
8-
{
9-
plugins: { vitest },
10-
rules: {
11-
...vitest.configs.recommended.rules,
12-
'vitest/expect-expect': 'warn',
13-
},
14-
},
15-
]
5+
export default [...rootConfig]
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
// @ts-check
22

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

6-
export default [
7-
...rootConfig,
8-
{
9-
plugins: { vitest },
10-
rules: {
11-
...vitest.configs.recommended.rules,
12-
'vitest/expect-expect': 'warn',
13-
},
14-
},
15-
]
5+
export default [...rootConfig]

packages/query-codemods/eslint.config.js

-7
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,4 @@ export default [
1616
'sort-imports': 'off',
1717
},
1818
},
19-
{
20-
plugins: { vitest },
21-
rules: {
22-
...vitest.configs.recommended.rules,
23-
'vitest/expect-expect': 'warn',
24-
},
25-
},
2619
]

packages/query-core/eslint.config.js

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
// @ts-check
22

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

6-
export default [
7-
...rootConfig,
8-
{
9-
plugins: { vitest },
10-
rules: {
11-
...vitest.configs.recommended.rules,
12-
'vitest/expect-expect': 'warn',
13-
},
14-
},
15-
]
5+
export default [...rootConfig]

packages/query-core/src/__tests__/notifyManager.test.tsx

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
1+
import {
2+
afterEach,
3+
assertType,
4+
beforeEach,
5+
describe,
6+
expect,
7+
expectTypeOf,
8+
it,
9+
vi,
10+
} from 'vitest'
211
import { createNotifyManager } from '../notifyManager'
312
import { sleep } from './utils'
413

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

84-
someFn('im happy', 4)
85-
86-
// @ts-expect-error
87-
someFn('im not happy', false)
93+
expectTypeOf(someFn).parameters.toEqualTypeOf<Parameters<typeof fn>>()
94+
assertType<Parameters<typeof someFn>>(['im happy', 4])
95+
assertType<Parameters<typeof someFn>>([
96+
'im not happy',
97+
// @ts-expect-error
98+
false,
99+
])
88100
})
89101

90102
it('should use custom batch notify function', async () => {

packages/query-core/src/__tests__/queryClient.test-d.tsx

+30-35
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, expectTypeOf, it } from 'vitest'
1+
import { assertType, describe, expectTypeOf, it } from 'vitest'
22
import { QueryClient } from '../queryClient'
33
import type { MutationFilters, QueryFilters, Updater } from '../utils'
44
import type { Mutation } from '../mutation'
@@ -42,10 +42,10 @@ describe('getQueryData', () => {
4242
})
4343

4444
it('should only allow Arrays to be passed', () => {
45-
const queryKey = 'key'
46-
const queryClient = new QueryClient()
47-
// @ts-expect-error TS2345: Argument of type 'string' is not assignable to parameter of type 'QueryKey'
48-
return queryClient.getQueryData(queryKey)
45+
assertType<Parameters<QueryClient['getQueryData']>>([
46+
// @ts-expect-error TS2345: Argument of type 'string' is not assignable to parameter of type 'QueryKey'
47+
{ queryKey: 'key' },
48+
])
4949
})
5050
})
5151

@@ -171,22 +171,26 @@ describe('fetchInfiniteQuery', () => {
171171
})
172172

173173
it('should not allow passing getNextPageParam without pages', () => {
174-
new QueryClient().fetchInfiniteQuery({
175-
queryKey: ['key'],
176-
queryFn: () => Promise.resolve('string'),
177-
initialPageParam: 1,
178-
getNextPageParam: () => 1,
179-
})
174+
assertType<Parameters<QueryClient['fetchInfiniteQuery']>>([
175+
{
176+
queryKey: ['key'],
177+
queryFn: () => Promise.resolve('string'),
178+
initialPageParam: 1,
179+
getNextPageParam: () => 1,
180+
},
181+
])
180182
})
181183

182184
it('should not allow passing pages without getNextPageParam', () => {
183-
// @ts-expect-error Property 'getNextPageParam' is missing
184-
return new QueryClient().fetchInfiniteQuery({
185-
queryKey: ['key'],
186-
queryFn: () => Promise.resolve('string'),
187-
initialPageParam: 1,
188-
pages: 5,
189-
})
185+
assertType<Parameters<QueryClient['fetchInfiniteQuery']>>([
186+
// @ts-expect-error Property 'getNextPageParam' is missing
187+
{
188+
queryKey: ['key'],
189+
queryFn: () => Promise.resolve('string'),
190+
initialPageParam: 1,
191+
pages: 5,
192+
},
193+
])
190194
})
191195
})
192196

@@ -506,26 +510,17 @@ describe('fully typed usage', () => {
506510

507511
describe('invalidateQueries', () => {
508512
it('shows type error when queryKey is a wrong type in invalidateQueries', () => {
509-
const queryClient = new QueryClient()
510-
511-
queryClient.invalidateQueries()
512-
513-
queryClient.invalidateQueries({
514-
queryKey: ['1'],
515-
})
516-
517-
queryClient.invalidateQueries({
513+
assertType<Parameters<QueryClient['invalidateQueries']>>([])
514+
assertType<Parameters<QueryClient['invalidateQueries']>>([
515+
{ queryKey: ['1'] },
516+
])
517+
assertType<Parameters<QueryClient['invalidateQueries']>>([
518518
// @ts-expect-error
519-
queryKey: '1',
520-
})
521-
522-
queryClient.invalidateQueries({
523-
// @ts-expect-error
524-
queryKey: {},
525-
})
519+
{ queryKey: '1' },
520+
])
526521
})
527522
it('needs queryKey to be an array (#8684)', () => {
528-
new QueryClient().invalidateQueries({
523+
assertType<Parameters<QueryClient['invalidateQueries']>>({
529524
// @ts-expect-error key is not an array
530525
queryKey: { foo: true },
531526
})
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
// @ts-check
22

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

6-
export default [
7-
...rootConfig,
8-
{
9-
plugins: { vitest },
10-
rules: {
11-
...vitest.configs.recommended.rules,
12-
'vitest/expect-expect': 'warn',
13-
},
14-
},
15-
]
5+
export default [...rootConfig]

0 commit comments

Comments
 (0)