mirror of
https://github.com/microsoft/playwright.git
synced 2024-09-11 20:37:54 +03:00
fix(clock): throw for invalid date (#31356)
Fixes https://github.com/microsoft/playwright/issues/31354
This commit is contained in:
parent
c6aab05bd5
commit
5fc56283a6
@ -58,6 +58,8 @@ function parseTime(time: string | number | Date): { timeNumber?: number, timeStr
|
||||
return { timeNumber: time };
|
||||
if (typeof time === 'string')
|
||||
return { timeString: time };
|
||||
if (!isFinite(time.getTime()))
|
||||
throw new Error(`Invalid date: ${time}`);
|
||||
return { timeNumber: time.getTime() };
|
||||
}
|
||||
|
||||
|
@ -148,5 +148,8 @@ function parseTime(epoch: string | number | undefined): number {
|
||||
return 0;
|
||||
if (typeof epoch === 'number')
|
||||
return epoch;
|
||||
return new Date(epoch).getTime();
|
||||
const parsed = new Date(epoch);
|
||||
if (!isFinite(parsed.getTime()))
|
||||
throw new Error(`Invalid date: ${epoch}`);
|
||||
return parsed.getTime();
|
||||
}
|
||||
|
@ -245,6 +245,11 @@ it.describe('stubTimers', () => {
|
||||
expect(await page.evaluate(() => Date.now())).toBe(1400);
|
||||
});
|
||||
|
||||
it('should throw for invalid date', async ({ page }) => {
|
||||
await expect(page.clock.setSystemTime(new Date('invalid'))).rejects.toThrow('Invalid date: Invalid Date');
|
||||
await expect(page.clock.setSystemTime('invalid')).rejects.toThrow('clock.setSystemTime: Invalid date: invalid');
|
||||
});
|
||||
|
||||
it('replaces global setTimeout', async ({ page, calls }) => {
|
||||
await page.evaluate(async () => {
|
||||
setTimeout(window.stub, 1000);
|
||||
|
Loading…
Reference in New Issue
Block a user