Skip to content

Commit 53c954d

Browse files
authored
Merge branch 'main' into feature/feat/callback-for-retryOnMount
2 parents b40fb96 + 61b9763 commit 53c954d

87 files changed

Lines changed: 1358 additions & 1303 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/eslint/no-unstable-deps.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Examples of **incorrect** code for this rule:
2222

2323
```tsx
2424
/* eslint "@tanstack/query/no-unstable-deps": "warn" */
25-
import { useCallback } from 'React'
25+
import { useCallback } from 'react'
2626
import { useMutation } from '@tanstack/react-query'
2727

2828
function Component() {
@@ -38,7 +38,7 @@ Examples of **correct** code for this rule:
3838

3939
```tsx
4040
/* eslint "@tanstack/query/no-unstable-deps": "warn" */
41-
import { useCallback } from 'React'
41+
import { useCallback } from 'react'
4242
import { useMutation } from '@tanstack/react-query'
4343

4444
function Component() {

docs/reference/QueryClient.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ This distinction is more a "convenience" for ts devs that know which structure w
250250

251251
## `queryClient.setQueryData`
252252

253-
`setQueryData` is a synchronous function that can be used to immediately update a query's cached data. If the query does not exist, it will be created. **If the query is not utilized by a query hook in the default `gcTime` of 5 minutes, the query will be garbage collected**. To update multiple queries at once and match query keys partially, you need to use [`queryClient.setQueriesData`](#queryclientsetqueriesdata) instead.
253+
`setQueryData` is a synchronous function that can be used to immediately update a query's cached data. If the query does not exist, it will be created. **If the query is not utilized by a query hook within the default `gcTime`, the query will be garbage collected. If the default `gcTime` has not been configured, it defaults to 5 minutes.** To update multiple queries at once and match query keys partially, you need to use [`queryClient.setQueriesData`](#queryclientsetqueriesdata) instead.
254254

255255
> The difference between using `setQueryData` and `fetchQuery` is that `setQueryData` is sync and assumes that you already synchronously have the data available. If you need to fetch the data asynchronously, it's suggested that you either refetch the query key or use `fetchQuery` to handle the asynchronous fetch.
256256

eslint.config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,14 @@ export default [
5252
plugins: { vitest },
5353
rules: {
5454
...vitest.configs.recommended.rules,
55+
'vitest/consistent-test-it': [
56+
'error',
57+
{ fn: 'it', withinDescribe: 'it' },
58+
],
5559
'vitest/no-standalone-expect': [
5660
'error',
5761
{
58-
additionalTestBlockFunctions: ['testIf'],
62+
additionalTestBlockFunctions: ['itIf'],
5963
},
6064
],
6165
},

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertType, describe, expectTypeOf, it, test } from 'vitest'
1+
import { assertType, describe, expectTypeOf, it } from 'vitest'
22
import { queryKey } from '@tanstack/query-test-utils'
33
import { QueryClient, dataTagSymbol } from '@tanstack/query-core'
44
import { infiniteQueryOptions } from '../infinite-query-options'
@@ -139,7 +139,7 @@ describe('infiniteQueryOptions', () => {
139139
>()
140140
})
141141

142-
test('should not be allowed to be passed to non-infinite query functions', () => {
142+
it('should not be allowed to be passed to non-infinite query functions', () => {
143143
const key = queryKey()
144144
const queryClient = new QueryClient()
145145
const options = infiniteQueryOptions({
@@ -166,7 +166,7 @@ describe('infiniteQueryOptions', () => {
166166
)
167167
})
168168

169-
test('allow optional initialData function', () => {
169+
it('should allow optional initialData function', () => {
170170
const key = queryKey()
171171
const initialData: { example: boolean } | undefined = { example: true }
172172
const queryOptions = infiniteQueryOptions({
@@ -185,7 +185,7 @@ describe('infiniteQueryOptions', () => {
185185
>()
186186
})
187187

188-
test('allow optional initialData object', () => {
188+
it('should allow optional initialData object', () => {
189189
const key = queryKey()
190190
const initialData: { example: boolean } | undefined = { example: true }
191191
const queryOptions = infiniteQueryOptions({

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { TestBed } from '@angular/core/testing'
2-
import { afterEach, beforeEach, describe, expectTypeOf, test, vi } from 'vitest'
2+
import { afterEach, beforeEach, describe, expectTypeOf, it, vi } from 'vitest'
33
import { provideZonelessChangeDetection } from '@angular/core'
44
import { queryKey, sleep } from '@tanstack/query-test-utils'
55
import { QueryClient, injectInfiniteQuery, provideTanStackQuery } from '..'
@@ -23,7 +23,7 @@ describe('injectInfiniteQuery', () => {
2323
vi.useRealTimers()
2424
})
2525

26-
test('should narrow type after isSuccess', () => {
26+
it('should narrow type after isSuccess', () => {
2727
const key = queryKey()
2828
const query = TestBed.runInInjectionContext(() => {
2929
return injectInfiniteQuery(() => ({

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

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import { TestBed } from '@angular/core/testing'
2-
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
3-
import { Injector, provideZonelessChangeDetection } from '@angular/core'
2+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
3+
import {
4+
Component,
5+
Injector,
6+
provideZonelessChangeDetection,
7+
} from '@angular/core'
8+
import { render } from '@testing-library/angular'
49
import { queryKey, sleep } from '@tanstack/query-test-utils'
510
import { QueryClient, injectInfiniteQuery, provideTanStackQuery } from '..'
6-
import { expectSignals } from './test-utils'
711

812
describe('injectInfiniteQuery', () => {
913
let queryClient: QueryClient
@@ -23,48 +27,47 @@ describe('injectInfiniteQuery', () => {
2327
vi.useRealTimers()
2428
})
2529

26-
test('should properly execute infinite query', async () => {
30+
it('should properly execute infinite query', async () => {
2731
const key = queryKey()
28-
const query = TestBed.runInInjectionContext(() => {
29-
return injectInfiniteQuery(() => ({
32+
33+
@Component({
34+
template: `
35+
<div>status: {{ query.status() }}</div>
36+
<div>pages: {{ query.data()?.pages?.join(', ') ?? 'none' }}</div>
37+
`,
38+
})
39+
class Page {
40+
readonly query = injectInfiniteQuery(() => ({
3041
queryKey: key,
3142
queryFn: ({ pageParam }) =>
3243
sleep(10).then(() => 'data on page ' + pageParam),
3344
initialPageParam: 0,
3445
getNextPageParam: () => 12,
3546
}))
36-
})
47+
}
3748

38-
expectSignals(query, {
39-
data: undefined,
40-
status: 'pending',
41-
})
49+
const rendered = await render(Page)
4250

43-
await vi.advanceTimersByTimeAsync(11)
51+
expect(rendered.getByText('status: pending')).toBeInTheDocument()
52+
expect(rendered.getByText('pages: none')).toBeInTheDocument()
4453

45-
expectSignals(query, {
46-
data: {
47-
pageParams: [0],
48-
pages: ['data on page 0'],
49-
},
50-
status: 'success',
51-
})
54+
await vi.advanceTimersByTimeAsync(11)
55+
rendered.fixture.detectChanges()
56+
expect(rendered.getByText('status: success')).toBeInTheDocument()
57+
expect(rendered.getByText('pages: data on page 0')).toBeInTheDocument()
5258

53-
void query.fetchNextPage()
59+
rendered.fixture.componentInstance.query.fetchNextPage()
5460

5561
await vi.advanceTimersByTimeAsync(11)
56-
57-
expectSignals(query, {
58-
data: {
59-
pageParams: [0, 12],
60-
pages: ['data on page 0', 'data on page 12'],
61-
},
62-
status: 'success',
63-
})
62+
rendered.fixture.detectChanges()
63+
expect(rendered.getByText('status: success')).toBeInTheDocument()
64+
expect(
65+
rendered.getByText('pages: data on page 0, data on page 12'),
66+
).toBeInTheDocument()
6467
})
6568

6669
describe('injection context', () => {
67-
test('throws NG0203 with descriptive error outside injection context', () => {
70+
it('should throw NG0203 with descriptive error outside injection context', () => {
6871
const key = queryKey()
6972
expect(() => {
7073
injectInfiniteQuery(() => ({
@@ -77,7 +80,7 @@ describe('injectInfiniteQuery', () => {
7780
}).toThrow(/NG0203(.*?)injectInfiniteQuery/)
7881
})
7982

80-
test('can be used outside injection context when passing an injector', () => {
83+
it('should be usable outside injection context when passing an injector', () => {
8184
const key = queryKey()
8285
const query = injectInfiniteQuery(
8386
() => ({

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

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import { TestBed } from '@angular/core/testing'
2-
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
3-
import { Injector, provideZonelessChangeDetection } from '@angular/core'
2+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
3+
import {
4+
Component,
5+
Injector,
6+
provideZonelessChangeDetection,
7+
} from '@angular/core'
8+
import { render } from '@testing-library/angular'
49
import { queryKey, sleep } from '@tanstack/query-test-utils'
510
import {
611
QueryClient,
@@ -28,31 +33,41 @@ describe('injectIsFetching', () => {
2833
vi.useRealTimers()
2934
})
3035

31-
test('Returns number of fetching queries', async () => {
36+
it('should return the number of fetching queries', async () => {
3237
const key = queryKey()
33-
const isFetching = TestBed.runInInjectionContext(() => {
34-
injectQuery(() => ({
38+
39+
@Component({
40+
template: `<div>fetching: {{ isFetching() }}</div>`,
41+
})
42+
class Page {
43+
readonly query = injectQuery(() => ({
3544
queryKey: key,
3645
queryFn: () => sleep(100).then(() => 'Some data'),
3746
}))
38-
return injectIsFetching()
39-
})
47+
readonly isFetching = injectIsFetching()
48+
}
49+
50+
const rendered = await render(Page)
51+
52+
expect(rendered.getByText('fetching: 0')).toBeInTheDocument()
53+
54+
await vi.advanceTimersByTimeAsync(0)
55+
rendered.fixture.detectChanges()
56+
expect(rendered.getByText('fetching: 1')).toBeInTheDocument()
4057

41-
expect(isFetching()).toStrictEqual(0)
42-
await vi.advanceTimersByTimeAsync(1)
43-
expect(isFetching()).toStrictEqual(1)
44-
await vi.advanceTimersByTimeAsync(100)
45-
expect(isFetching()).toStrictEqual(0)
58+
await vi.advanceTimersByTimeAsync(101)
59+
rendered.fixture.detectChanges()
60+
expect(rendered.getByText('fetching: 0')).toBeInTheDocument()
4661
})
4762

4863
describe('injection context', () => {
49-
test('throws NG0203 with descriptive error outside injection context', () => {
64+
it('should throw NG0203 with descriptive error outside injection context', () => {
5065
expect(() => {
5166
injectIsFetching()
5267
}).toThrow(/NG0203(.*?)injectIsFetching/)
5368
})
5469

55-
test('can be used outside injection context when passing an injector', () => {
70+
it('should be usable outside injection context when passing an injector', () => {
5671
expect(
5772
injectIsFetching(undefined, {
5873
injector: TestBed.inject(Injector),

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

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
1+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
22
import { TestBed } from '@angular/core/testing'
3-
import { Injector, provideZonelessChangeDetection } from '@angular/core'
3+
import {
4+
Component,
5+
Injector,
6+
provideZonelessChangeDetection,
7+
} from '@angular/core'
8+
import { render } from '@testing-library/angular'
49
import { queryKey, sleep } from '@tanstack/query-test-utils'
510
import {
611
QueryClient,
@@ -28,37 +33,43 @@ describe('injectIsMutating', () => {
2833
vi.useRealTimers()
2934
})
3035

31-
test('should properly return isMutating state', async () => {
36+
it('should properly return isMutating state', async () => {
3237
const key = queryKey()
33-
const [mutation, isMutating] = TestBed.runInInjectionContext(() => [
34-
injectMutation(() => ({
38+
39+
@Component({
40+
template: `<div>mutating: {{ isMutating() }}</div>`,
41+
})
42+
class Page {
43+
readonly mutation = injectMutation(() => ({
3544
mutationKey: key,
3645
mutationFn: (params: { par1: string }) => sleep(10).then(() => params),
37-
})),
38-
injectIsMutating(),
39-
])
46+
}))
47+
readonly isMutating = injectIsMutating()
48+
}
4049

41-
expect(isMutating()).toBe(0)
50+
const rendered = await render(Page)
4251

43-
mutation.mutate({
44-
par1: 'par1',
45-
})
52+
expect(rendered.getByText('mutating: 0')).toBeInTheDocument()
53+
54+
rendered.fixture.componentInstance.mutation.mutate({ par1: 'par1' })
4655

47-
expect(isMutating()).toBe(0)
4856
await vi.advanceTimersByTimeAsync(0)
49-
expect(isMutating()).toBe(1)
57+
rendered.fixture.detectChanges()
58+
expect(rendered.getByText('mutating: 1')).toBeInTheDocument()
59+
5060
await vi.advanceTimersByTimeAsync(11)
51-
expect(isMutating()).toBe(0)
61+
rendered.fixture.detectChanges()
62+
expect(rendered.getByText('mutating: 0')).toBeInTheDocument()
5263
})
5364

5465
describe('injection context', () => {
55-
test('throws NG0203 with descriptive error outside injection context', () => {
66+
it('should throw NG0203 with descriptive error outside injection context', () => {
5667
expect(() => {
5768
injectIsMutating()
5869
}).toThrow(/NG0203(.*?)injectIsMutating/)
5970
})
6071

61-
test('can be used outside injection context when passing an injector', () => {
72+
it('should be usable outside injection context when passing an injector', () => {
6273
expect(
6374
injectIsMutating(undefined, {
6475
injector: TestBed.inject(Injector),

0 commit comments

Comments
 (0)