mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
5d9cff0331
Previously, we used an option to allow duplicate templates, if that option was passed, we would always replace the existing template with the new template, and if it wasn't, we would always throw an error even if the template's content was the same. Allowing to replace a template with a different one is problematic, as it may or may not have already been compiled, which may cause various problems. On the other hand, if the template is the same, there is no point in throwing an error, as we can just silently ignore the second addition.
41 lines
1.6 KiB
TypeScript
41 lines
1.6 KiB
TypeScript
import { TemplateSet } from "../../src/app/template_set";
|
|
import { renderToString, snapshotTemplate, TestContext } from "../helpers";
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// basic validation
|
|
// -----------------------------------------------------------------------------
|
|
|
|
describe("basic validation", () => {
|
|
test("error if no template with given name", () => {
|
|
const context = new TemplateSet();
|
|
expect(() => context.getTemplate("invalidname")).toThrow("Missing template");
|
|
});
|
|
|
|
test("cannot add a different template with the same name", () => {
|
|
const context = new TemplateSet();
|
|
context.addTemplate("test", `<t/>`);
|
|
// Same template with the same name is fine
|
|
expect(() => context.addTemplate("test", "<t/>")).not.toThrow();
|
|
// Different template with the same name crashes
|
|
expect(() => context.addTemplate("test", "<div/>")).toThrow("already defined");
|
|
});
|
|
|
|
test("invalid xml", () => {
|
|
const template = "<div>";
|
|
expect(() => snapshotTemplate(template)).toThrow("Invalid XML in template");
|
|
});
|
|
|
|
test("missing template in template set", () => {
|
|
const context = new TestContext();
|
|
const template = `<t t-call="othertemplate" />`;
|
|
|
|
context.addTemplate("template", template);
|
|
expect(() => context.renderToString("template")).toThrowError("Missing");
|
|
});
|
|
|
|
test("error when unknown directive", () => {
|
|
const template = `<div t-best-beer="rochefort 10">test</div>`;
|
|
expect(() => renderToString(template)).toThrow("Unknown QWeb directive: 't-best-beer'");
|
|
});
|
|
});
|