[IMP] qweb: add registerTemplate method

This commit is contained in:
Géry Debongnie
2019-09-12 10:38:53 +02:00
parent 5bf7a5c671
commit d57017b6ed
4 changed files with 47 additions and 2 deletions
+20
View File
@@ -11,6 +11,7 @@ import { normalize, renderToDOM, renderToString, trim, nextTick } from "../helpe
let qweb: QWeb;
beforeEach(() => {
QWeb.TEMPLATES = {};
qweb = new QWeb();
});
@@ -1278,3 +1279,22 @@ describe("update on event bus", () => {
expect(fn).toBeCalledTimes(1);
});
});
describe("global template registration", () => {
test("can register template globally", () => {
expect.assertions(5);
let qweb = new QWeb();
try {
qweb.render("mytemplate");
} catch (e) {
expect(e.message).toMatch("Template mytemplate does not exist");
}
expect(qweb.templates.mytemplate).toBeUndefined();
QWeb.registerTemplate("mytemplate", "<div>global</div>");
expect(qweb.templates.mytemplate).toBeDefined();
const vnode = qweb.render("mytemplate");
expect(vnode.sel).toBe("div");
expect((vnode as any).children[0].text).toBe("global");
});
});
-1
View File
@@ -53,7 +53,6 @@ describe("RouteComponent", () => {
await nextTick();
expect(fixture.innerHTML).toBe("<div><span>Users</span></div>");
expect(env.qweb.templates[ROUTE_COMPONENT_TEMPLATE_NAME].fn.toString()).toMatchSnapshot();
});
test("can render parameterized route", async () => {