Skip to content

Commit af4ff17

Browse files
committed
test(poll): pins Math.random in background poll test, fixes qa-3 tag
1 parent c0bc23c commit af4ff17

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tests/services/poll.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ describe("createPollCoordinator", () => {
121121
});
122122

123123
it("continues polling when document is hidden (notifications gate enabled)", async () => {
124+
const randomSpy = vi.spyOn(Math, "random").mockReturnValue(0.5); // jitter = 0
124125
const fetchAll = makeFetchAll();
125126

126127
await createRoot(async (dispose) => {
@@ -132,14 +133,16 @@ describe("createPollCoordinator", () => {
132133
// Hide document
133134
setDocumentVisible(false);
134135

135-
// Advance past the interval
136-
vi.advanceTimersByTime(90_000);
136+
// Advance past the interval (60s with 0 jitter)
137+
vi.advanceTimersByTime(61_000);
137138
await Promise.resolve();
138139

139140
// Should have fetched while hidden (background refresh)
140141
expect(fetchAll.mock.calls.length).toBeGreaterThan(callsAfterInit);
141142
dispose();
142143
});
144+
145+
randomSpy.mockRestore();
143146
});
144147

145148
it("triggers immediate refresh on re-visible after >2 minutes hidden", async () => {
@@ -474,7 +477,7 @@ describe("createPollCoordinator", () => {
474477
});
475478
});
476479

477-
// ── qa-3: doFetch skipped path — no restore (reconciliation replaces snapshot/restore) ──
480+
// ── qa-3a: doFetch skipped path — no restore (reconciliation replaces snapshot/restore) ──
478481

479482
it("skipped fetch does NOT call pushError for previous errors (no restore logic)", async () => {
480483
mockPushError.mockClear();

0 commit comments

Comments
 (0)