Skip to content

Commit 19dce13

Browse files
authored
Merge branch 'main' into main
2 parents 14c83b2 + 25623e2 commit 19dce13

File tree

45 files changed

+686
-517
lines changed

Some content is hidden

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

45 files changed

+686
-517
lines changed

.eslintrc.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const config = {
4949
'Promisable', // Our public interface
5050
'extralight', // Our public interface
5151
'codemod', // We support our codemod
52+
'typecheck', // Field of vite.config.ts
5253

5354
'TSES', // @typescript-eslint package's interface
5455
'tsup', // We use tsup as builder

examples/angular/basic/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@angular/platform-browser": "^17.1.3",
1818
"@angular/platform-browser-dynamic": "^17.1.3",
1919
"@angular/router": "^17.1.3",
20-
"@tanstack/angular-query-experimental": "^5.26.0",
20+
"@tanstack/angular-query-experimental": "^5.26.2",
2121
"rxjs": "^7.8.1",
2222
"tslib": "^2.6.2",
2323
"zone.js": "^0.14.3"
@@ -26,7 +26,7 @@
2626
"@angular-devkit/build-angular": "^17.1.3",
2727
"@angular/cli": "^17.1.3",
2828
"@angular/compiler-cli": "^17.1.3",
29-
"@tanstack/angular-query-devtools-experimental": "^5.26.0",
29+
"@tanstack/angular-query-devtools-experimental": "^5.26.2",
3030
"typescript": "5.2.2"
3131
},
3232
"overrides": {

examples/angular/infinite-query-with-max-pages/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@angular/platform-browser": "^17.1.3",
1818
"@angular/platform-browser-dynamic": "^17.1.3",
1919
"@angular/router": "^17.1.3",
20-
"@tanstack/angular-query-experimental": "^5.26.0",
20+
"@tanstack/angular-query-experimental": "^5.26.2",
2121
"rxjs": "^7.8.1",
2222
"tslib": "^2.6.2",
2323
"zone.js": "^0.14.3"
@@ -26,7 +26,7 @@
2626
"@angular-devkit/build-angular": "^17.1.3",
2727
"@angular/cli": "^17.1.3",
2828
"@angular/compiler-cli": "^17.1.3",
29-
"@tanstack/angular-query-devtools-experimental": "^5.26.0",
29+
"@tanstack/angular-query-devtools-experimental": "^5.26.2",
3030
"typescript": "5.2.2"
3131
},
3232
"overrides": {

examples/angular/router/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@angular/platform-browser": "^17.1.3",
1818
"@angular/platform-browser-dynamic": "^17.1.3",
1919
"@angular/router": "^17.1.3",
20-
"@tanstack/angular-query-experimental": "^5.26.0",
20+
"@tanstack/angular-query-experimental": "^5.26.2",
2121
"rxjs": "^7.8.1",
2222
"tslib": "^2.6.2",
2323
"zone.js": "^0.14.3"
@@ -26,7 +26,7 @@
2626
"@angular-devkit/build-angular": "^17.1.3",
2727
"@angular/cli": "^17.1.3",
2828
"@angular/compiler-cli": "^17.1.3",
29-
"@tanstack/angular-query-devtools-experimental": "^5.26.0",
29+
"@tanstack/angular-query-devtools-experimental": "^5.26.2",
3030
"typescript": "5.2.2"
3131
},
3232
"overrides": {

examples/angular/simple/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@angular/platform-browser": "^17.1.3",
1818
"@angular/platform-browser-dynamic": "^17.1.3",
1919
"@angular/router": "^17.1.3",
20-
"@tanstack/angular-query-experimental": "^5.26.0",
20+
"@tanstack/angular-query-experimental": "^5.26.2",
2121
"rxjs": "^7.8.1",
2222
"tslib": "^2.6.2",
2323
"zone.js": "^0.14.3"
@@ -26,7 +26,7 @@
2626
"@angular-devkit/build-angular": "^17.1.3",
2727
"@angular/cli": "^17.1.3",
2828
"@angular/compiler-cli": "^17.1.3",
29-
"@tanstack/angular-query-devtools-experimental": "^5.26.0",
29+
"@tanstack/angular-query-devtools-experimental": "^5.26.2",
3030
"typescript": "5.2.2"
3131
},
3232
"overrides": {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/angular-query-devtools-experimental",
3-
"version": "5.26.0",
3+
"version": "5.26.2",
44
"description": "Developer tools to interact with and visualize the TanStack/angular-query cache",
55
"author": "Arnoud de Vries",
66
"license": "MIT",

packages/angular-query-devtools-experimental/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ export default defineConfig({
99
environment: 'jsdom',
1010
coverage: { enabled: true, provider: 'istanbul', include: ['src/**/*'] },
1111
typecheck: { enabled: true },
12+
restoreMocks: true,
1213
},
1314
})

packages/angular-query-experimental/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tanstack/angular-query-experimental",
3-
"version": "5.26.0",
3+
"version": "5.26.2",
44
"description": "Signals for managing, caching and syncing asynchronous and remote data in Angular",
55
"author": "Arnoud de Vries",
66
"license": "MIT",

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

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, input, signal } from '@angular/core'
22
import { QueryClient } from '@tanstack/query-core'
33
import { TestBed } from '@angular/core/testing'
4-
import { describe, expect, test, vi } from 'vitest'
4+
import { describe, expect, vi } from 'vitest'
55
import { By } from '@angular/platform-browser'
66
import { injectMutation } from '../inject-mutation'
77
import { provideAngularQuery } from '../providers'
@@ -402,4 +402,57 @@ describe('injectMutation', () => {
402402
expect(mutation1!.options.mutationKey).toEqual(['fake', 'value'])
403403
expect(mutation2!.options.mutationKey).toEqual(['fake', 'updatedValue'])
404404
})
405+
406+
describe('throwOnError', () => {
407+
test('should evaluate throwOnError when mutation is expected to throw', async () => {
408+
const err = new Error('Expected mock error. All is well!')
409+
const boundaryFn = vi.fn()
410+
const { mutate } = TestBed.runInInjectionContext(() => {
411+
return injectMutation(() => ({
412+
mutationKey: ['fake'],
413+
mutationFn: () => {
414+
return Promise.reject(err)
415+
},
416+
throwOnError: boundaryFn,
417+
}))
418+
})
419+
420+
mutate()
421+
422+
await resolveMutations()
423+
424+
expect(boundaryFn).toHaveBeenCalledTimes(1)
425+
expect(boundaryFn).toHaveBeenCalledWith(err)
426+
})
427+
})
428+
429+
test('should throw when throwOnError is true', async () => {
430+
const err = new Error('Expected mock error. All is well!')
431+
const { mutateAsync } = TestBed.runInInjectionContext(() => {
432+
return injectMutation(() => ({
433+
mutationKey: ['fake'],
434+
mutationFn: () => {
435+
return Promise.reject(err)
436+
},
437+
throwOnError: true,
438+
}))
439+
})
440+
441+
await expect(() => mutateAsync()).rejects.toThrowError(err)
442+
})
443+
444+
test('should throw when throwOnError function returns true', async () => {
445+
const err = new Error('Expected mock error. All is well!')
446+
const { mutateAsync } = TestBed.runInInjectionContext(() => {
447+
return injectMutation(() => ({
448+
mutationKey: ['fake'],
449+
mutationFn: () => {
450+
return Promise.reject(err)
451+
},
452+
throwOnError: () => true,
453+
}))
454+
})
455+
456+
await expect(() => mutateAsync()).rejects.toThrowError(err)
457+
})
405458
})

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

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,64 @@ describe('injectQuery', () => {
201201
flush()
202202
}))
203203

204+
describe('throwOnError', () => {
205+
test('should evaluate throwOnError when query is expected to throw', fakeAsync(() => {
206+
const boundaryFn = vi.fn()
207+
TestBed.runInInjectionContext(() => {
208+
return injectQuery(() => ({
209+
queryKey: ['key12'],
210+
queryFn: rejectFetcher,
211+
throwOnError: boundaryFn,
212+
}))
213+
})
214+
215+
flush()
216+
217+
expect(boundaryFn).toHaveBeenCalledTimes(1)
218+
expect(boundaryFn).toHaveBeenCalledWith(
219+
Error('Some error'),
220+
expect.objectContaining({
221+
state: expect.objectContaining({ status: 'error' }),
222+
}),
223+
)
224+
}))
225+
226+
test('should throw when throwOnError is true', fakeAsync(() => {
227+
TestBed.runInInjectionContext(() => {
228+
return injectQuery(() => ({
229+
queryKey: ['key13'],
230+
queryFn: rejectFetcher,
231+
throwOnError: true,
232+
}))
233+
})
234+
235+
expect(() => {
236+
flush()
237+
}).toThrowError('Some error')
238+
flush()
239+
}))
240+
241+
test('should throw when throwOnError function returns true', fakeAsync(() => {
242+
TestBed.runInInjectionContext(() => {
243+
return injectQuery(() => ({
244+
queryKey: ['key14'],
245+
queryFn: rejectFetcher,
246+
throwOnError: () => true,
247+
}))
248+
})
249+
250+
expect(() => {
251+
flush()
252+
}).toThrowError('Some error')
253+
flush()
254+
}))
255+
})
256+
204257
test('should set state to error when queryFn returns reject promise', fakeAsync(() => {
205258
const query = TestBed.runInInjectionContext(() => {
206259
return injectQuery(() => ({
207260
retry: false,
208-
queryKey: ['key13'],
261+
queryKey: ['key15'],
209262
queryFn: rejectFetcher,
210263
}))
211264
})
@@ -238,7 +291,7 @@ describe('injectQuery', () => {
238291
})
239292

240293
flush()
241-
await fixture.detectChanges()
294+
fixture.detectChanges()
242295

243296
expect(fixture.debugElement.nativeElement.textContent).toEqual(
244297
'signal-input-required-test',

0 commit comments

Comments
 (0)