Skip to content

Commit a590d49

Browse files
authored
test(browser): stabilize basic interval fixture (#1423)
1 parent 4d1e262 commit a590d49

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

e2e/browser-mode/fixtures/basic/tests/async.test.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,23 @@ describe('Async operations', () => {
5959
it('should handle setInterval', async () => {
6060
let count = 0;
6161

62-
const intervalId = globalThis.setInterval(() => {
63-
count++;
64-
}, 20);
65-
66-
await sleep(120);
67-
globalThis.clearInterval(intervalId);
62+
await new Promise<void>((resolve, reject) => {
63+
const intervalId = globalThis.setInterval(() => {
64+
count++;
65+
if (count >= 2) {
66+
globalThis.clearTimeout(timeoutId);
67+
globalThis.clearInterval(intervalId);
68+
resolve();
69+
}
70+
}, 20);
71+
72+
const timeoutId = globalThis.setTimeout(() => {
73+
globalThis.clearInterval(intervalId);
74+
reject(
75+
new Error(`Expected interval to tick at least twice, got ${count}`),
76+
);
77+
}, 1000);
78+
});
6879

6980
expect(count).toBeGreaterThanOrEqual(2);
7081
});

0 commit comments

Comments
 (0)