diff --git a/test/e2e/tests/metrics/unlock-wallet.spec.js b/test/e2e/tests/metrics/unlock-wallet.spec.js index 3961bb3a94ce..2e4b9f5ed3eb 100644 --- a/test/e2e/tests/metrics/unlock-wallet.spec.js +++ b/test/e2e/tests/metrics/unlock-wallet.spec.js @@ -40,15 +40,26 @@ describe('Unlock wallet', function () { await unlockWallet(driver); await waitForAccountRendered(driver); const events = await getEventPayloads(driver, mockedEndpoint); - assert.equal(events.length, 3); - assertBatchValue(events[0], 'Home', '/'); - assertBatchValue(events[1], 'Unlock Page', '/unlock'); - assertBatchValue(events[2], 'Home', '/'); + const sortedEvents = sortEventsByTime(events); + await assert.equal(sortedEvents.length, 3); + assertBatchValue(sortedEvents[0], 'Home', '/'); + assertBatchValue(sortedEvents[1], 'Unlock Page', '/unlock'); + assertBatchValue(sortedEvents[2], 'Home', '/'); }, ); }); }); +function sortEventsByTime(events) { + events.sort((event1, event2) => { + const timestamp1 = new Date(event1.timestamp); + const timestamp2 = new Date(event2.timestamp); + // Compare timestamps, return -1 for earlier, 1 for later, 0 for equal + return timestamp1 - timestamp2; + }); + return events; +} + function assertBatchValue(event, assertedTitle, assertedPath) { const { title, path } = event.context.page; assert.equal(title, assertedTitle);