-
Notifications
You must be signed in to change notification settings - Fork 411
Closed
Labels
Description
@testing-library/jest-domversion: 5.11.9 (latest)nodeversion: n/anpm(oryarn) version: n/a
Relevant code or config:
import "@testing-library/jest-dom/extend-expect";
import React from "react";
import { render } from "@testing-library/react";
test("demo test", () => {
const { container } = render(<div className="empty" />);
// this assertion passes
expect(container).toContainHTML('<div class="empty"></div>');
// this one fails, even though it references the same structure
// expect(container).toContainHTML('<div class="empty" />');
});Reproduction:
https://codesandbox.io/s/contains-html-assertion-demo-7nd5n?file=/src/__tests__/hello.js:0-343
Suggested solution:
toContainHTML matcher treats expected content as a string. I figured that this normalization fixes the matching:
function normalize(content) {
const div = document.createElement('div');
div.innerHTML = content;
return div.innerHTML;
}
expect(container).toContainHTML(normalize('<div class="empty" />')); // passes Perhaps the matcher inside could apply this normalization
gnapse