From 0e56392b34f9497b5123492b1ba27382e5ccc93d Mon Sep 17 00:00:00 2001 From: Derek Nance Date: Tue, 7 Oct 2025 15:13:33 -0500 Subject: [PATCH] [PM-13422] Fix flaky test around sync time (#16773) --- .../src/platform/sync/default-sync.service.spec.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libs/common/src/platform/sync/default-sync.service.spec.ts b/libs/common/src/platform/sync/default-sync.service.spec.ts index 352e45b88b..193a5a2d2d 100644 --- a/libs/common/src/platform/sync/default-sync.service.spec.ts +++ b/libs/common/src/platform/sync/default-sync.service.spec.ts @@ -329,10 +329,8 @@ describe("DefaultSyncService", () => { // Mock the value of this observable because it's used in `syncProfile`. Without it, the test breaks. keyConnectorService.convertAccountRequired$ = of(false); - // Baseline date/time to compare sync time to, in order to avoid needing to use some kind of fake date provider. - const beforeSync = Date.now(); + jest.useFakeTimers({ now: Date.now() }); - // send it! await sut.fullSync(true, defaultSyncOptions); expectUpdateCallCount(mockUserState, 1); @@ -340,9 +338,10 @@ describe("DefaultSyncService", () => { const updateCall = mockUserState.update.mock.calls[0]; // Get the first argument to update(...) -- this will be the date callback that returns the date of the last successful sync const dateCallback = updateCall[0]; - const actualTime = dateCallback() as Date; + const actualDate = dateCallback() as Date; - expect(Math.abs(actualTime.getTime() - beforeSync)).toBeLessThan(1); + expect(actualDate.getTime()).toEqual(jest.now()); + jest.useRealTimers(); }); it("updates last sync time when no sync is necessary", async () => {