mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
@@ -90,12 +90,12 @@ function isValidProp(prop, propDef): boolean {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
let result = isValidProp(prop, propDef.type);
|
let result = isValidProp(prop, propDef.type);
|
||||||
if (propDef.type === Array) {
|
if (propDef.type === Array && propDef.element) {
|
||||||
for (let i = 0, iLen = prop.length; i < iLen; i++) {
|
for (let i = 0, iLen = prop.length; i < iLen; i++) {
|
||||||
result = result && isValidProp(prop[i], propDef.element);
|
result = result && isValidProp(prop[i], propDef.element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (propDef.type === Object) {
|
if (propDef.type === Object && propDef.shape) {
|
||||||
const shape = propDef.shape;
|
const shape = propDef.shape;
|
||||||
for (let key in shape) {
|
for (let key in shape) {
|
||||||
result = result && isValidProp(prop[key], shape[key]);
|
result = result && isValidProp(prop[key], shape[key]);
|
||||||
|
|||||||
@@ -581,6 +581,32 @@ describe("props validation", () => {
|
|||||||
}).toThrow();
|
}).toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("props with type array, and no element", async () => {
|
||||||
|
class TestWidget extends Widget {
|
||||||
|
static props = { myprop: { type: Array } };
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
QWeb.utils.validateProps(TestWidget, { myprop: [1] });
|
||||||
|
}).not.toThrow();
|
||||||
|
expect(() => {
|
||||||
|
QWeb.utils.validateProps(TestWidget, { myprop: 1 });
|
||||||
|
}).toThrow(`Props 'myprop' of invalid type in component 'TestWidget'`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("props with type object, and no shape", async () => {
|
||||||
|
class TestWidget extends Widget {
|
||||||
|
static props = { myprop: { type: Object } };
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
QWeb.utils.validateProps(TestWidget, { myprop: { a: 3 } });
|
||||||
|
}).not.toThrow();
|
||||||
|
expect(() => {
|
||||||
|
QWeb.utils.validateProps(TestWidget, { myprop: false });
|
||||||
|
}).toThrow(`Props 'myprop' of invalid type in component 'TestWidget'`);
|
||||||
|
});
|
||||||
|
|
||||||
test("props: extra props cause an error", async () => {
|
test("props: extra props cause an error", async () => {
|
||||||
class TestWidget extends Widget {
|
class TestWidget extends Widget {
|
||||||
static props = ["message"];
|
static props = ["message"];
|
||||||
|
|||||||
Reference in New Issue
Block a user