diff --git a/src/component.ts b/src/component.ts index ab6d43b7..a915a508 100644 --- a/src/component.ts +++ b/src/component.ts @@ -458,7 +458,9 @@ export class Component { 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; diff --git a/src/qweb_core.ts b/src/qweb_core.ts index f8bcd733..c3f4f4da 100644 --- a/src/qweb_core.ts +++ b/src/qweb_core.ts @@ -149,7 +149,6 @@ export class QWeb { if (data) { this.addTemplates(data); } - this.addTemplate("default", "
"); } static addDirective(directive: Directive) { diff --git a/tests/component.test.ts b/tests/component.test.ts index be3b4120..57efd19d 100644 --- a/tests/component.test.ts +++ b/tests/component.test.ts @@ -25,6 +25,7 @@ let env: Env; beforeEach(() => { fixture = makeTestFixture(); env = makeTestEnv(); + env.qweb.addTemplate("Widget", "
"); env.qweb.addTemplate( "Counter", `
` @@ -83,6 +84,19 @@ describe("basic widget properties", () => { expect(fixture.innerHTML).toBe("
"); }); + test("crashes if it cannot find a template", async () => { + expect.assertions(1); + class SomeWidget extends Component {} + 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); diff --git a/tests/qweb.test.ts b/tests/qweb.test.ts index 61d03aac..d34187b8 100644 --- a/tests/qweb.test.ts +++ b/tests/qweb.test.ts @@ -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([]); }); });