[FIX] web: renderToElement should be detached

Before this commit, the element returned by the function
renderToElement, it was still attached to the parent <div> added in the
render function.

Now, the element returned is detached.

Part of task~3443861

Part-of: odoo/odoo#130467
This commit is contained in:
Jorge Pinna Puissant
2023-08-11 14:32:31 +02:00
committed by Samuel Degueldre
parent e338487028
commit f30be0732e
2 changed files with 8 additions and 1 deletions
+3 -1
View File
@@ -3,7 +3,9 @@
import { blockDom, markup } from "@odoo/owl";
export function renderToElement(template, context = {}) {
return render(template, context).firstElementChild;
const el = render(template, context).firstElementChild;
el?.remove();
return el;
}
export function renderToFragment(template, context = {}) {
@@ -16,6 +16,11 @@ QUnit.module("utils", () => {
</t>`
);
const compiledTemplate = renderToElement("test.render.template.1");
assert.strictEqual(
compiledTemplate.parentElement,
null,
"compiledTemplate.parentElement must be empty"
);
assert.strictEqual(
compiledTemplate.nodeType,
Node.ELEMENT_NODE,