to-contain-html.js 966 B

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.toContainHTML = toContainHTML;
  6. var _utils = require("./utils");
  7. function getNormalizedHtml(container, htmlText) {
  8. const div = container.ownerDocument.createElement('div');
  9. div.innerHTML = htmlText;
  10. return div.innerHTML;
  11. }
  12. function toContainHTML(container, htmlText) {
  13. (0, _utils.checkHtmlElement)(container, toContainHTML, this);
  14. if (typeof htmlText !== 'string') {
  15. throw new Error(`.toContainHTML() expects a string value, got ${htmlText}`);
  16. }
  17. return {
  18. pass: container.outerHTML.includes(getNormalizedHtml(container, htmlText)),
  19. message: () => {
  20. return [this.utils.matcherHint(`${this.isNot ? '.not' : ''}.toContainHTML`, 'element', ''), 'Expected:', // eslint-disable-next-line babel/new-cap
  21. ` ${this.utils.EXPECTED_COLOR(htmlText)}`, 'Received:', ` ${this.utils.printReceived(container.cloneNode(true))}`].join('\n');
  22. }
  23. };
  24. }