[FIX] component: crashes if no template can be found

closes #178
This commit is contained in:
Géry Debongnie
2019-06-14 23:33:45 +02:00
parent 9cacc78ad7
commit b201ef8162
4 changed files with 18 additions and 3 deletions
+3 -1
View File
@@ -458,7 +458,9 @@ export class Component<T extends Env, Props extends {}, State extends {}> {
p = p.__proto__;
}
if (p === Component) {
this.template = "default";
throw new Error(
`Could not find template for component "${this.constructor.name}"`
);
} else {
tmap[name] = template;
this.template = template;
-1
View File
@@ -149,7 +149,6 @@ export class QWeb {
if (data) {
this.addTemplates(data);
}
this.addTemplate("default", "<div></div>");
}
static addDirective(directive: Directive) {
+14
View File
@@ -25,6 +25,7 @@ let env: Env;
beforeEach(() => {
fixture = makeTestFixture();
env = makeTestEnv();
env.qweb.addTemplate("Widget", "<div></div>");
env.qweb.addTemplate(
"Counter",
`<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>");
});
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 () => {
const counter = new Counter(env);
await counter.mount(fixture);
+1 -1
View File
@@ -1105,7 +1105,7 @@ describe("loading templates", () => {
test("does not crash if string does not have templates", () => {
const data = "";
qweb.addTemplates(data);
expect(Object.keys(qweb.templates)).toEqual(["default"]);
expect(Object.keys(qweb.templates)).toEqual([]);
});
});