Sha256: ddd3e4b9c81666481f2667dacb7db3b3d40eb5a74adab2a938df17cb5d8652f7

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

// detect side-effects of cloning svg elements in IE9-11
let ieSVGInnerHTML = (() => {
  if (!document.createElementNS) {
    return false;
  }
  let div = document.createElement('div');
  let node = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
  div.appendChild(node);
  let clone = div.cloneNode(true);
  return clone.innerHTML === '<svg xmlns="http://www.w3.org/2000/svg" />';
})();

function normalizeInnerHTML(actualHTML) {
  if (ieSVGInnerHTML) {
    // Replace `<svg xmlns="http://www.w3.org/2000/svg" height="50%" />` with `<svg height="50%"></svg>`, etc.
    // drop namespace attribute
    // replace self-closing elements
    actualHTML = actualHTML
      .replace(/ xmlns="[^"]+"/, '')
      .replace(
        /<([^ >]+) [^\/>]*\/>/gi,
        (tag, tagName) => `${tag.slice(0, tag.length - 3)}></${tagName}>`
      );
  }

  return actualHTML;
}

export default function equalInnerHTML(assert, fragment, html) {
  let actualHTML = normalizeInnerHTML(fragment.innerHTML);

  assert.pushResult({
    result: actualHTML === html,
    actual: actualHTML,
    expected: html,
  });
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
discourse-ember-source-3.6.0.0 dist/es/internal-test-helpers/lib/equal-inner-html.js
discourse-ember-source-3.5.1.1 dist/es/internal-test-helpers/lib/equal-inner-html.js
discourse-ember-source-3.5.1.0 dist/dist/es/internal-test-helpers/lib/equal-inner-html.js