Skip to content

The agent that grows with you

test(desktop): pin document.hasFocus in background-sync backstop tests

Tekniumf535a4f28401
diff --git a/apps/desktop/src/app/contrib/hooks/use-background-sync.test.ts b/apps/desktop/src/app/contrib/hooks/use-background-sync.test.ts
index 47a67e6be25..1b70bb29bd0 100644
--- a/apps/desktop/src/app/contrib/hooks/use-background-sync.test.ts
+++ b/apps/desktop/src/app/contrib/hooks/use-background-sync.test.ts
@@ -113,6 +113,12 @@ function renderSync(
)
}
+beforeEach(() => {
+ // visiblePoll only ticks while the window is actively viewed; jsdom's
+ // document.hasFocus() is not reliably true, so pin it for these tests.
+ vi.spyOn(document, 'hasFocus').mockReturnValue(true)
+})
+
afterEach(() => {
cleanup()
vi.clearAllTimers()
@@ -124,6 +130,7 @@ afterEach(() => {
setMessagingSessions([])
setBusy(false)
vi.clearAllMocks()
+ vi.restoreAllMocks()
clearAllSessionStates()
})