mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] component: proper error message in dev mode in some cases
This commit is contained in:
committed by
Samuel Degueldre
parent
d9b189bcba
commit
b159a073d9
@@ -39,6 +39,11 @@ export const validateProps = function (name: string | typeof Component, props: a
|
|||||||
typeof name !== "string" ? name : parent.constructor.components[name]
|
typeof name !== "string" ? name : parent.constructor.components[name]
|
||||||
) as typeof Component;
|
) as typeof Component;
|
||||||
|
|
||||||
|
if (!ComponentClass) {
|
||||||
|
// this is an error, wrong component. We silently return here instead so the
|
||||||
|
// error is triggered by the usual path ('component' function)
|
||||||
|
return;
|
||||||
|
}
|
||||||
applyDefaultProps(props, ComponentClass);
|
applyDefaultProps(props, ComponentClass);
|
||||||
|
|
||||||
let propsDef = getPropDescription(ComponentClass.props);
|
let propsDef = getPropDescription(ComponentClass.props);
|
||||||
|
|||||||
@@ -1,5 +1,18 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`basics display a nice error if it cannot find component (in dev mode) 1`] = `
|
||||||
|
"function anonymous(bdom, helpers
|
||||||
|
) {
|
||||||
|
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||||
|
|
||||||
|
return function template(ctx, node, key = \\"\\") {
|
||||||
|
const props1 = {}
|
||||||
|
helpers.validateProps(\`SomeMispelledComponent\`, props1, ctx)
|
||||||
|
return component(\`SomeMispelledComponent\`, props1, key + \`__1\`, node, ctx);
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`basics display a nice error if it cannot find component 1`] = `
|
exports[`basics display a nice error if it cannot find component 1`] = `
|
||||||
"function anonymous(bdom, helpers
|
"function anonymous(bdom, helpers
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -81,6 +81,29 @@ describe("basics", () => {
|
|||||||
expect(mockConsoleWarn).toBeCalledTimes(1);
|
expect(mockConsoleWarn).toBeCalledTimes(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("display a nice error if it cannot find component (in dev mode)", async () => {
|
||||||
|
const info = console.info;
|
||||||
|
console.info = jest.fn(() => {}); // dev mode message
|
||||||
|
class SomeComponent extends Component {}
|
||||||
|
class Parent extends Component {
|
||||||
|
static template = xml`<SomeMispelledComponent />`;
|
||||||
|
static components = { SomeComponent };
|
||||||
|
}
|
||||||
|
let error: Error;
|
||||||
|
try {
|
||||||
|
await mount(Parent, fixture, { dev: true });
|
||||||
|
} catch (e) {
|
||||||
|
error = e as Error;
|
||||||
|
}
|
||||||
|
expect(error!).toBeDefined();
|
||||||
|
expect(error!.message).toBe('Cannot find the definition of component "SomeMispelledComponent"');
|
||||||
|
expect(console.error).toBeCalledTimes(0);
|
||||||
|
expect(mockConsoleError).toBeCalledTimes(0);
|
||||||
|
expect(mockConsoleWarn).toBeCalledTimes(1);
|
||||||
|
expect(console.info).toBeCalledTimes(1);
|
||||||
|
console.info = info;
|
||||||
|
});
|
||||||
|
|
||||||
test("simple catchError", async () => {
|
test("simple catchError", async () => {
|
||||||
class Boom extends Component {
|
class Boom extends Component {
|
||||||
static template = xml`<div t-esc="a.b.c"/>`;
|
static template = xml`<div t-esc="a.b.c"/>`;
|
||||||
|
|||||||
Reference in New Issue
Block a user