From fe34ba00a639ad933a7b79fda532e33213ea5805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Wed, 16 Sep 2020 22:21:20 +0200 Subject: [PATCH] [FIX] component: properly validate multiple props Because of a "break" statement instead of "continue", the check for valid props was stopping as soon as it met an optional props, which kind of invalidate the whole system. closes #717 --- src/component/props_validation.ts | 2 +- tests/component/props_validation.test.ts | 25 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/component/props_validation.ts b/src/component/props_validation.ts index 996ffb03..4fad585e 100644 --- a/src/component/props_validation.ts +++ b/src/component/props_validation.ts @@ -37,7 +37,7 @@ QWeb.utils.validateProps = function (Widget, props: Object) { if (propsDef[propName] && !propsDef[propName].optional) { throw new Error(`Missing props '${propName}' (component '${Widget.name}')`); } else { - break; + continue; } } let isValid; diff --git a/tests/component/props_validation.test.ts b/tests/component/props_validation.test.ts index 8973cb2e..98526cfc 100644 --- a/tests/component/props_validation.test.ts +++ b/tests/component/props_validation.test.ts @@ -786,6 +786,31 @@ describe("props validation", () => { await nextTick(); expect(fixture.innerHTML).toBe("
4
"); }); + + test("mix of optional and mandatory", async () => { + class Child extends Component { + static props = { + optional: { type: String, optional: true }, + mandatory: Number, + }; + static template = xml`
`; + } + + class App extends Component { + static components = { Child }; + static template = xml`
`; + } + + const w = new App(undefined, {}); + let error; + try { + await w.mount(fixture); + } catch (e) { + error = e; + } + expect(error).toBeDefined(); + expect(error.message).toBe("Missing props 'mandatory' (component 'Child')"); + }); }); describe("default props", () => {