From 1479e5a066fc5bfb32b90a28f4ba15df31d22207 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Wed, 3 Jan 2024 12:34:44 +0100 Subject: [PATCH] fix: throw in expect() if unsupported type is passed to text matcher --- playwright/_impl/_assertions.py | 3 +++ tests/async/test_assertions.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/playwright/_impl/_assertions.py b/playwright/_impl/_assertions.py index 73dc76000..a8f2f5bf2 100644 --- a/playwright/_impl/_assertions.py +++ b/playwright/_impl/_assertions.py @@ -18,6 +18,7 @@ from playwright._impl._api_structures import ExpectedTextValue, FrameExpectOptions from playwright._impl._connection import format_call_log +from playwright._impl._errors import Error from playwright._impl._fetch import APIResponse from playwright._impl._helper import is_textual_mime_type from playwright._impl._locator import Locator @@ -795,4 +796,6 @@ def to_expected_text_values( item, match_substring, normalize_white_space, ignore_case ) ) + else: + raise Error("value must be a string or regular expression") return out diff --git a/tests/async/test_assertions.py b/tests/async/test_assertions.py index 49b860309..774d60de5 100644 --- a/tests/async/test_assertions.py +++ b/tests/async/test_assertions.py @@ -96,6 +96,13 @@ async def test_assertions_locator_to_contain_text(page: Page, server: Server) -> await expect(page.locator("div")).to_contain_text(["ext 1", re.compile("ext3")]) +async def test_assertions_locator_to_contain_text_should_throw_if_arg_is_unsupported_type( + page: Page, +) -> None: + with pytest.raises(Error, match="value must be a string or regular expression"): + await expect(page.locator("div")).to_contain_text(1) # type: ignore + + async def test_assertions_locator_to_have_attribute(page: Page, server: Server) -> None: await page.goto(server.EMPTY_PAGE) await page.set_content("
kek
")