1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-06 00:13:28 +00:00

[PM-13422] Fix flaky test around sync time (#16773)

This commit is contained in:
Derek Nance
2025-10-07 15:13:33 -05:00
committed by GitHub
parent b0179bd105
commit 0e56392b34

View File

@@ -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 () => {