mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
+3
-1
@@ -458,7 +458,9 @@ export class Component<T extends Env, Props extends {}, State extends {}> {
|
|||||||
p = p.__proto__;
|
p = p.__proto__;
|
||||||
}
|
}
|
||||||
if (p === Component) {
|
if (p === Component) {
|
||||||
this.template = "default";
|
throw new Error(
|
||||||
|
`Could not find template for component "${this.constructor.name}"`
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
tmap[name] = template;
|
tmap[name] = template;
|
||||||
this.template = template;
|
this.template = template;
|
||||||
|
|||||||
@@ -149,7 +149,6 @@ export class QWeb {
|
|||||||
if (data) {
|
if (data) {
|
||||||
this.addTemplates(data);
|
this.addTemplates(data);
|
||||||
}
|
}
|
||||||
this.addTemplate("default", "<div></div>");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static addDirective(directive: Directive) {
|
static addDirective(directive: Directive) {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ let env: Env;
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = makeTestFixture();
|
fixture = makeTestFixture();
|
||||||
env = makeTestEnv();
|
env = makeTestEnv();
|
||||||
|
env.qweb.addTemplate("Widget", "<div></div>");
|
||||||
env.qweb.addTemplate(
|
env.qweb.addTemplate(
|
||||||
"Counter",
|
"Counter",
|
||||||
`<div><t t-esc="state.counter"/><button t-on-click="inc">Inc</button></div>`
|
`<div><t t-esc="state.counter"/><button t-on-click="inc">Inc</button></div>`
|
||||||
@@ -83,6 +84,19 @@ describe("basic widget properties", () => {
|
|||||||
expect(fixture.innerHTML).toBe("<div></div>");
|
expect(fixture.innerHTML).toBe("<div></div>");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("crashes if it cannot find a template", async () => {
|
||||||
|
expect.assertions(1);
|
||||||
|
class SomeWidget extends Component<any, any, any> {}
|
||||||
|
const widget = new SomeWidget(env);
|
||||||
|
try {
|
||||||
|
await widget.mount(fixture);
|
||||||
|
} catch (e) {
|
||||||
|
expect(e.message).toBe(
|
||||||
|
'Could not find template for component "SomeWidget"'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test("can be clicked on and updated", async () => {
|
test("can be clicked on and updated", async () => {
|
||||||
const counter = new Counter(env);
|
const counter = new Counter(env);
|
||||||
await counter.mount(fixture);
|
await counter.mount(fixture);
|
||||||
|
|||||||
+1
-1
@@ -1105,7 +1105,7 @@ describe("loading templates", () => {
|
|||||||
test("does not crash if string does not have templates", () => {
|
test("does not crash if string does not have templates", () => {
|
||||||
const data = "";
|
const data = "";
|
||||||
qweb.addTemplates(data);
|
qweb.addTemplates(data);
|
||||||
expect(Object.keys(qweb.templates)).toEqual(["default"]);
|
expect(Object.keys(qweb.templates)).toEqual([]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user