Skip to content

Commit 7f35a42

Browse files
authored
fix: throw in expect() if unsupported type is passed to text matcher (#2221)
1 parent 1928691 commit 7f35a42

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

playwright/_impl/_assertions.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from playwright._impl._api_structures import ExpectedTextValue, FrameExpectOptions
2020
from playwright._impl._connection import format_call_log
21+
from playwright._impl._errors import Error
2122
from playwright._impl._fetch import APIResponse
2223
from playwright._impl._helper import is_textual_mime_type
2324
from playwright._impl._locator import Locator
@@ -793,4 +794,6 @@ def to_expected_text_values(
793794
out.append(
794795
expected_regex(item, match_substring, normalize_white_space, ignoreCase)
795796
)
797+
else:
798+
raise Error("value must be a string or regular expression")
796799
return out

tests/async/test_assertions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ async def test_assertions_locator_to_contain_text(page: Page, server: Server) ->
9696
await expect(page.locator("div")).to_contain_text(["ext 1", re.compile("ext3")])
9797

9898

99+
async def test_assertions_locator_to_contain_text_should_throw_if_arg_is_unsupported_type(
100+
page: Page,
101+
) -> None:
102+
with pytest.raises(Error, match="value must be a string or regular expression"):
103+
await expect(page.locator("div")).to_contain_text(1) # type: ignore
104+
105+
99106
async def test_assertions_locator_to_have_attribute(page: Page, server: Server) -> None:
100107
await page.goto(server.EMPTY_PAGE)
101108
await page.set_content("<div id=foobar>kek</div>")

0 commit comments

Comments
 (0)