qunit-dom icon indicating copy to clipboard operation
qunit-dom copied to clipboard

Add `hasHtml` to assert an element has specific HTML

Open fastfedora opened this issue 9 months ago • 0 comments

When testing whether dynamic content is rendered correctly as HTML, it would be useful to have a hasHtml assertion.

This would be the same as hasText except that instead of testing against textContent, it would test against innerHTML.trim().

The workaround for now is use assert.equal. For instance:

const html =  'Where you put your <b>emphasis</b> is up to you.',

// cause this HTML to be rendered

assert.equal(document.querySelector('.message').innerHTML.trim(), html);

However, having an hasHtml built-in would be more idiomatic:

assert.dom('.message').hasHtml(html);

fastfedora avatar Sep 20 '23 09:09 fastfedora