Skip to content

Commit ad3bc84

Browse files
authored
test(angular-query-experimental/withDevtools): add test for 'No QueryClient found' throw when 'loadDevtools' is 'true' without a 'QueryClient' (#10544)
1 parent 50d08de commit ad3bc84

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,33 @@ describe('withDevtools feature', () => {
153153
},
154154
)
155155

156+
it("should throw 'No QueryClient found' when 'loadDevtools' is 'true' and no 'QueryClient' is provided", async () => {
157+
const consoleErrorSpy = vi
158+
.spyOn(console, 'error')
159+
.mockImplementation(() => undefined)
160+
161+
TestBed.configureTestingModule({
162+
providers: [
163+
provideZonelessChangeDetection(),
164+
withDevtools(() => ({
165+
loadDevtools: true,
166+
})).ɵproviders,
167+
],
168+
})
169+
170+
TestBed.inject(ENVIRONMENT_INITIALIZER)
171+
TestBed.tick()
172+
await vi.dynamicImportSettled()
173+
174+
expect(mockTanstackQueryDevtools).not.toHaveBeenCalled()
175+
expect(consoleErrorSpy).toHaveBeenCalledWith(
176+
'Install @tanstack/query-devtools or reinstall without --omit=optional.',
177+
expect.objectContaining({ message: 'No QueryClient found' }),
178+
)
179+
180+
consoleErrorSpy.mockRestore()
181+
})
182+
156183
it('should not continue loading devtools after injector is destroyed', async () => {
157184
TestBed.configureTestingModule({
158185
providers: [

0 commit comments

Comments
 (0)