Skip to content

Commit

Permalink
test: fix flaky test (#940) (#945)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercy811 authored Jan 13, 2025
1 parent 6410052 commit 8f1c31f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/analytics-browser/test/browser-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -613,13 +613,16 @@ describe('browser-client', () => {
expect(extendedLastEventTime > eventTime1).toBeTruthy();

// send another event just before session expires (again)
// Mock Date.now() because isNewSession() depends on it
const dateNowMocked = jest.spyOn(Date, 'now').mockImplementation(() => extendedLastEventTime + 15);
await new Promise<void>((resolve) =>
// eslint-disable-next-line @typescript-eslint/no-misused-promises
setTimeout(async () => {
await client.track('test 2').promise;
resolve();
}, 15),
);
dateNowMocked.mockRestore();

// assert session id is unchanged
expect(client.config.sessionId).toBe(firstSessionId);
Expand Down

0 comments on commit 8f1c31f

Please sign in to comment.