Hi!
I am currently trying to write tests for some components I have been writing for Phoenix. I generally feel like I understand the testing story quite well, but one annoying thing about having HTML templates is the whitespace and assert html ~= ~S(rendered template)
requiring the exact whitespace including all tabs. This results into me having to try around to find the exact tab levels.
In particular, something like
def render(_assigns) do
<div class="bg-white shadow sm:rounded-lg">
Content
</div>
end
requires a test assert like
assert html =~ ~S( <div class="bg-white shadow sm:rounded-lg">
This is the card content.
</div>)
That is, well, not ideal.
I have looked through the docs trying to find a sigil or function that strips all tabs and newlines from a string, but only found String.trim/1
that only works on leading and trailing whitespace.
Is there any way to accomplish this? I have looked at the Surface library tests too and they have whitespace all over the place as well.
Any help and pointer would be much appreciated!
Cheers