chore: update noscript test (#11749)

pull/11750/head
Rich Harris 4 months ago committed by GitHub
parent b87fd61729
commit 329c10eb6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -84,7 +84,7 @@ export function normalize_html(
.replace(/\s?onerror="this.__e=event"|\s?onload="this.__e=event"/g, '')
.trim();
clean_children(node);
return node.innerHTML.replace(/<\/?noscript\/?>/g, '');
return node.innerHTML;
} catch (err) {
throw new Error(`Failed to normalize HTML:\n${html}`);
}

@ -1,38 +1,27 @@
import { test } from '../../test';
export default test({
ssrHtml: `
<noscript>foo</noscript>
<div>foo<noscript>foo</noscript></div>
<div>foo<div>foo<noscript>foo</noscript></div></div>
`,
test({ assert, target, compileOptions, variant }) {
test({ assert, target, variant }) {
// if created on client side, should not build noscript
if (variant === 'dom') {
assert.equal(target.querySelectorAll('noscript').length, 0);
assert.htmlEqual(
target.innerHTML,
`
<div>foo</div>
<div>foo<div>foo</div></div>
`
);
} else {
assert.equal(target.querySelectorAll('noscript').length, 3);
assert.htmlEqual(
target.innerHTML,
`
<noscript>foo</noscript>
<div>foo<noscript>foo</noscript></div>
<div>foo<div>foo<noscript>foo</noscript></div></div>
`
);
}
// it's okay not to remove the node during hydration
// will not be seen by user anyway
remove_noscript(target);
assert.htmlEqual(
target.innerHTML,
`
<div>foo</div>
<div>foo<div>foo</div></div>
`
);
}
});
/**
* @param {HTMLElement} target
*/
function remove_noscript(target) {
target.querySelectorAll('noscript').forEach((elem) => {
elem.parentNode?.removeChild(elem);
});
}

Loading…
Cancel
Save