[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
This commit is contained in:
Géry Debongnie
2020-09-16 22:21:20 +02:00
committed by aab-odoo
parent e5e7790530
commit fe34ba00a6
2 changed files with 26 additions and 1 deletions
+25
View File
@@ -786,6 +786,31 @@ describe("props validation", () => {
await nextTick();
expect(fixture.innerHTML).toBe("<div><div>4</div></div>");
});
test("mix of optional and mandatory", async () => {
class Child extends Component {
static props = {
optional: { type: String, optional: true },
mandatory: Number,
};
static template = xml` <div><t t-esc="props.mandatory"/></div>`;
}
class App extends Component {
static components = { Child };
static template = xml`<div><Child/></div>`;
}
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", () => {