mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] component: display better error message if render is empty
closes #446
This commit is contained in:
@@ -282,9 +282,7 @@ export class Component<T extends Env, Props extends {}> {
|
|||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
if (!(target instanceof HTMLElement)) {
|
if (!(target instanceof HTMLElement)) {
|
||||||
let message = `Component '${
|
let message = `Component '${this.constructor.name}' cannot be mounted: the target is not a valid DOM node.`;
|
||||||
this.constructor.name
|
|
||||||
}' cannot be mounted: the target is not a valid DOM node.`;
|
|
||||||
message += `\nMaybe the DOM is not ready yet? (in that case, you can use owl.utils.whenReady)`;
|
message += `\nMaybe the DOM is not ready yet? (in that case, you can use owl.utils.whenReady)`;
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
@@ -579,10 +577,14 @@ export class Component<T extends Env, Props extends {}> {
|
|||||||
__owl__.observer.allowMutations = false;
|
__owl__.observer.allowMutations = false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
fiber.vnode = __owl__.renderFn!(this, {
|
let vnode = __owl__.renderFn!(this, {
|
||||||
handlers: __owl__.boundHandlers,
|
handlers: __owl__.boundHandlers,
|
||||||
fiber: fiber
|
fiber: fiber
|
||||||
});
|
});
|
||||||
|
if (!vnode) {
|
||||||
|
throw new Error(`Rendering '${this.constructor.name}' did not return anything`);
|
||||||
|
}
|
||||||
|
fiber.vnode = vnode;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
fiber.handleError(e);
|
fiber.handleError(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -236,9 +236,7 @@ QWeb.addDirective({
|
|||||||
varCode = `{${content}}`;
|
varCode = `{${content}}`;
|
||||||
}
|
}
|
||||||
ctx.addLine(
|
ctx.addLine(
|
||||||
`this.recursiveFns['${subTemplateName}'].call(this, context, Object.assign({}, extra, {parentNode: c${
|
`this.recursiveFns['${subTemplateName}'].call(this, context, Object.assign({}, extra, {parentNode: c${ctx.parentNode}, fiber: {vars: ${varCode}, scope}}));`
|
||||||
ctx.parentNode
|
|
||||||
}, fiber: {vars: ${varCode}, scope}}));`
|
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -307,9 +305,7 @@ QWeb.addDirective({
|
|||||||
!node.children[0].hasAttribute("t-key");
|
!node.children[0].hasAttribute("t-key");
|
||||||
if (shouldWarn) {
|
if (shouldWarn) {
|
||||||
console.warn(
|
console.warn(
|
||||||
`Directive t-foreach should always be used with a t-key! (in template: '${
|
`Directive t-foreach should always be used with a t-key! (in template: '${ctx.templateName}')`
|
||||||
ctx.templateName
|
|
||||||
}')`
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,21 @@ describe("basic widget properties", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("display an error message if result of rendering is empty", async () => {
|
||||||
|
class SomeWidget extends Component<any, any> {
|
||||||
|
static template = xml`<t/>`;
|
||||||
|
}
|
||||||
|
const widget = new SomeWidget();
|
||||||
|
let error;
|
||||||
|
try {
|
||||||
|
await widget.mount(fixture);
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
|
expect(error).toBeDefined();
|
||||||
|
expect(error.message).toBe("Rendering 'SomeWidget' did not return anything");
|
||||||
|
});
|
||||||
|
|
||||||
test("crashes if it cannot find a template", async () => {
|
test("crashes if it cannot find a template", async () => {
|
||||||
expect.assertions(1);
|
expect.assertions(1);
|
||||||
class SomeWidget extends Component<any, any> {}
|
class SomeWidget extends Component<any, any> {}
|
||||||
|
|||||||
Reference in New Issue
Block a user