Skip to content

assert_dom should ignore whitespace just like assert_dom_equal #121

Closed
@jyeharry

Description

@jyeharry

In one of my views I have this:

<li><%= item.quantity %> &times; <%= item.product.title %></li>

My formatter automatically breaks this onto new lines like so:

      <li><%= item.quantity %>
        &times;
        <%= item.product.title %></li>

Because of this, running a test that contains this assertion fails:

assert_select "ul li", "#{item.quantity} \u00D7 #{products(:one).title}"

This is due to the text I'm passing to assert_select having no newlines in it, but in the view code there are newlines even though the browser actually drops those newlines.

So the test output is as follow:

Failure:
LineItemsControllerTest#test_should_create_line_item [test/controllers/line_items_controller_test.rb:27]:
--- expected
+++ actual
@@ -1 +1,3 @@
-"1 × The Pragmatic Programmer"
+"1
+        ×
+        The Pragmatic Programmer"
.
Expected 0 to be >= 1.

My current fix is to either turn off my formatter for that file, or to update the assertion to use regex and replace the spaces with \s+ like this:

assert_select "ul li", /#{item.quantity}\s+\u00D7\s+#{products(:one).title}/

However, the test should really treat excess whitespace the same as the browser does by dropping it.

Sounds like the same thing was done for assert_dom_equal in #84.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions