diff --git a/tests/async/test_evaluate.py b/tests/async/test_evaluate.py index 75156c167..0b2143769 100644 --- a/tests/async/test_evaluate.py +++ b/tests/async/test_evaluate.py @@ -223,12 +223,20 @@ async def test_evaluate_evaluate_date(page: Page) -> None: } -async def test_evaluate_roundtrip_date(page: Page) -> None: +async def test_evaluate_roundtrip_date_without_tzinfo(page: Page) -> None: date = datetime.fromisoformat("2020-05-27T01:31:38.506") result = await page.evaluate("date => date", date) assert result.timestamp() == date.timestamp() +async def test_evaluate_roundtrip_date(page: Page) -> None: + date = datetime.fromisoformat("2020-05-27T01:31:38.506").replace( + tzinfo=timezone.utc + ) + result = await page.evaluate("date => date", date) + assert result == date + + async def test_evaluate_roundtrip_date_with_tzinfo(page: Page) -> None: date = datetime.fromisoformat("2020-05-27T01:31:38.506") date = date.astimezone(timezone(timedelta(hours=4))) diff --git a/tests/async/test_jshandle.py b/tests/async/test_jshandle.py index 3ba9d0e9b..f18cbd633 100644 --- a/tests/async/test_jshandle.py +++ b/tests/async/test_jshandle.py @@ -14,7 +14,7 @@ import json import math -from datetime import datetime +from datetime import datetime, timezone from typing import Any, Dict from playwright.async_api import Page @@ -180,9 +180,8 @@ async def test_jshandle_json_value_work(page: Page) -> None: async def test_jshandle_json_value_work_with_dates(page: Page) -> None: handle = await page.evaluate_handle('() => new Date("2020-05-27T01:31:38.506Z")') json = await handle.json_value() - assert ( - json.timestamp() - == datetime.fromisoformat("2020-05-27T01:31:38.506").timestamp() + assert json == datetime.fromisoformat("2020-05-27T01:31:38.506").replace( + tzinfo=timezone.utc )