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

Add ability to match on entire html #85

Open
srcrip opened this issue Jun 14, 2024 · 3 comments
Open

Add ability to match on entire html #85

srcrip opened this issue Jun 14, 2024 · 3 comments

Comments

@srcrip
Copy link

srcrip commented Jun 14, 2024

To retain the ability to match on html instead of a selector, you can use a helper function like this:

  def assert_html(session, text) do
    assert render(session.view) =~ text

    session
  end

I think this should probably just be added in as it's own function in the Assertions module.

@germsvel
Copy link
Owner

germsvel commented Jul 3, 2024

Yeah, I'm not opposed to the library adding something like that. I think I would name it assert_text since we're asserting there's some text on the page. I'd be happy to review a PR If you're up for it.

@srcrip
Copy link
Author

srcrip commented Jul 8, 2024

I think assert_html may be preferable because assert_text implies plain text, ie, the html tags stripped away

@germsvel
Copy link
Owner

germsvel commented Jul 9, 2024

That's an interesting thought. I think we read it from different angles (which is always interesting!)

This is where my head's at 👇

As a user of the library, I would expect assert_html would help me assert that there's some HTML on the page:

assert_html(session, "<div>Could not find user</div>")

But my guess is that people want to use it as an "assert this text is on the page":

assert_text(session, "Could not find user")

I think that's also evidenced by the implementation you suggested -- where you have text as the argument being passed in (not html).

And if instead we wanted people to assert on HTML structure, I'm not sure I would recommend that. I typically recommend the opposite because asserting on HTML structure tends to make the tests brittle. For example, what if I add a class or id to my HTML in the first example? I've broken my test for no reason.

If we want to assert on certain aspects of HTML, we should use assert_has since it lets you target things with CSS selectors.

Finally, I think assert_text keeps in line with things like Wallaby's assert_text. We're not trying to keep in line with that, of course, but I do think assert_text might be what people expect to exist because of previous tools they've used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants