Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: throw in expect() if unsupported type is passed to text matcher #2221

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
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