enzymejs / enzyme-matchers

Jasmine/Jest assertions for enzyme
MIT License
892 stars 115 forks source link

Ignore whitespaces between tags by toHaveHTML #246

Closed astorije closed 6 years ago

astorije commented 6 years ago

At the moment, one has to write:

expect(component).toHaveHTML('<div class="row"><div class="col-1"><div class="tile"><div class="label">Label line</div><div class="content">Value line</div><div class="footnote">Footnote line</div></div></div></div>');

It would be really nice if this could be expanded in a more readable form and let the assertion ignore the blanks between tags:

expect(component).toHaveHTML(
  `<div class="row">
    <div class="col-1">
      <div class="tile">
        <div class="label">Label line</div>
        <div class="content">Value line</div>
        <div class="footnote">Footnote line</div>
      </div>
    </div>
  </div>`
);

I have this change locally and it works well, haven't noticed any downsides so far, so happy to turn it into a PR if you are open to that.

(I cannot use something like:

expect(component).toHaveHTML(
  '<div class="row">' +
    '<div class="col-1">' +
      /* ... */

because automated formatters such as Prettier reformat this accordingly.)

blainekasten commented 6 years ago

I think this would be a great addition! Would love to see the PR

astorije commented 6 years ago

Awesome, thanks @blainekasten, I did this in #250!