mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] app: validate props for root component in dev mode
Before this commit, only sub components were validated.
This commit is contained in:
@@ -60,6 +60,9 @@ export class App<
|
|||||||
|
|
||||||
mount(target: HTMLElement, options?: MountOptions): Promise<Component<P, E> & InstanceType<T>> {
|
mount(target: HTMLElement, options?: MountOptions): Promise<Component<P, E> & InstanceType<T>> {
|
||||||
App.validateTarget(target);
|
App.validateTarget(target);
|
||||||
|
if (this.dev) {
|
||||||
|
this.helpers.validateProps(this.Root, this.props);
|
||||||
|
}
|
||||||
const node = this.makeNode(this.Root, this.props);
|
const node = this.makeNode(this.Root, this.props);
|
||||||
const prom = this.mountNode(node, target, options);
|
const prom = this.mountNode(node, target, options);
|
||||||
this.root = node;
|
this.root = node;
|
||||||
|
|||||||
@@ -87,6 +87,22 @@ describe("props validation", () => {
|
|||||||
expect(error!.message).toBe("Invalid props for component 'SubComp': 'message' is missing");
|
expect(error!.message).toBe("Invalid props for component 'SubComp': 'message' is missing");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("validate props for root component", async () => {
|
||||||
|
class Root extends Component {
|
||||||
|
static props = ["message"];
|
||||||
|
static template = xml`<div t-esc="message"/>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
let error: Error;
|
||||||
|
try {
|
||||||
|
await mount(Root, fixture, { dev: true });
|
||||||
|
} catch (e) {
|
||||||
|
error = e as Error;
|
||||||
|
}
|
||||||
|
expect(error!).toBeDefined();
|
||||||
|
expect(error!.message).toBe("Invalid props for component 'Root': 'message' is missing");
|
||||||
|
});
|
||||||
|
|
||||||
test("validate simple types", async () => {
|
test("validate simple types", async () => {
|
||||||
const Tests = [
|
const Tests = [
|
||||||
{ type: Number, ok: 1, ko: "1" },
|
{ type: Number, ok: 1, ko: "1" },
|
||||||
|
|||||||
Reference in New Issue
Block a user