[FIX] web: renderToElement should always returns an element
Before this commit, when the first element of a template is a non fulfilled condition : '<t t-if="false"/>' The function renderToElement returns an empty text. This occurs because it returns the first child, which in this case is an empty text. Now, the function returns the first element. closes odoo/odoo#130858 X-original-commit: 8dabc4e1d5ebd94f6a315ce56b9bf60240dd7fdd Signed-off-by: Aaron Bohy (aab) <aab@odoo.com> Signed-off-by: Jorge Pinna Puissant (jpp) <jpp@odoo.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import { blockDom, markup } from "@odoo/owl";
|
||||
|
||||
export function renderToElement(template, context = {}) {
|
||||
return render(template, context).firstChild;
|
||||
return render(template, context).firstElementChild;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { renderToElement, renderToString } from "@web/core/utils/render";
|
||||
|
||||
QUnit.module("utils", () => {
|
||||
QUnit.module("render");
|
||||
|
||||
QUnit.test("renderToElement always returns an element", (assert) => {
|
||||
renderToString.app.addTemplate(
|
||||
"test.render.template.1",
|
||||
`<t t-if="False">
|
||||
<div>NotOk</div>
|
||||
</t>
|
||||
<t t-else="">
|
||||
<div>Ok</div>
|
||||
</t>`
|
||||
);
|
||||
const compiledTemplate = renderToElement("test.render.template.1");
|
||||
assert.strictEqual(
|
||||
compiledTemplate.nodeType,
|
||||
Node.ELEMENT_NODE,
|
||||
"compiledTemplate must be an element"
|
||||
);
|
||||
assert.strictEqual(compiledTemplate.outerHTML, "<div>Ok</div>");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user