Skip to content

Commit 8d979da

Browse files
authored
test(angular-query/devtools): add test for reactive 'theme' update (#10999)
1 parent 41b775f commit 8d979da

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
DevtoolsButtonPosition,
1818
DevtoolsErrorType,
1919
DevtoolsPosition,
20+
Theme,
2021
} from '@tanstack/query-devtools'
2122
import type { DevtoolsOptions } from '../devtools'
2223

@@ -28,6 +29,7 @@ const mockDevtoolsInstance = {
2829
setErrorTypes: vi.fn(),
2930
setButtonPosition: vi.fn(),
3031
setInitialIsOpen: vi.fn(),
32+
setTheme: vi.fn(),
3133
}
3234

3335
function MockTanstackQueryDevtools() {
@@ -433,6 +435,38 @@ describe('withDevtools feature', () => {
433435
expect(mockDevtoolsInstance.setInitialIsOpen).toHaveBeenCalledWith(true)
434436
})
435437

438+
it('should update theme', async () => {
439+
const theme = signal<Theme>('system')
440+
441+
TestBed.configureTestingModule({
442+
providers: [
443+
provideZonelessChangeDetection(),
444+
provideTanStackQuery(
445+
new QueryClient(),
446+
withDevtools(() => ({
447+
loadDevtools: true,
448+
theme: theme(),
449+
})),
450+
),
451+
],
452+
})
453+
454+
TestBed.inject(ENVIRONMENT_INITIALIZER)
455+
await vi.advanceTimersByTimeAsync(0)
456+
await vi.dynamicImportSettled()
457+
458+
TestBed.tick()
459+
460+
expect(mockDevtoolsInstance.setTheme).toHaveBeenCalledTimes(0)
461+
462+
theme.set('dark')
463+
464+
TestBed.tick()
465+
466+
expect(mockDevtoolsInstance.setTheme).toHaveBeenCalledTimes(1)
467+
expect(mockDevtoolsInstance.setTheme).toHaveBeenCalledWith('dark')
468+
})
469+
436470
it('should destroy devtools', async () => {
437471
const loadDevtools = signal(true)
438472

0 commit comments

Comments
 (0)