mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] qweb: add registerTemplate method
This commit is contained in:
@@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user