chore: update noscript test (#11749)

pull/11750/head
Rich Harris 1 year 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, '') .replace(/\s?onerror="this.__e=event"|\s?onload="this.__e=event"/g, '')
.trim(); .trim();
clean_children(node); clean_children(node);
return node.innerHTML.replace(/<\/?noscript\/?>/g, ''); return node.innerHTML;
} catch (err) { } catch (err) {
throw new Error(`Failed to normalize HTML:\n${html}`); throw new Error(`Failed to normalize HTML:\n${html}`);
} }

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

Loading…
Cancel
Save