Skip to content

Commit

Permalink
fix: throw in expect() if unsupported type is passed to text matcher (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt authored Jan 3, 2024
1 parent 1928691 commit 7f35a42
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions playwright/_impl/_assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -793,4 +794,6 @@ def to_expected_text_values(
out.append(
expected_regex(item, match_substring, normalize_white_space, ignoreCase)
)
else:
raise Error("value must be a string or regular expression")
return out
7 changes: 7 additions & 0 deletions tests/async/test_assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<div id=foobar>kek</div>")
Expand Down

0 comments on commit 7f35a42

Please sign in to comment.