Skip to content

Commit

Permalink
test: fix flaky test (#940)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercy811 authored Dec 27, 2024
1 parent 374d8aa commit 3ed0dfe
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 @@ -839,13 +839,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();
}, 10),
);
dateNowMocked.mockRestore();

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

0 comments on commit 3ed0dfe

Please sign in to comment.