mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] props validation: make it work through slots
A recent commit fixes the props validation code to make it work regardless of the rendering context (important with the recent t-call-context directive). Unfortunately, it then breaks props validation through slots, because it assumed that the parent node in the virtual node was the parent of the component, but it is not necessarily true. To fix this, we can use a simple property of the template functions: they are bound to the current instance of the component, so we can simply use "this"
This commit is contained in:
committed by
Sam Degueldre
parent
ab29b896eb
commit
17fb33475c
@@ -780,6 +780,32 @@ describe("props validation", () => {
|
||||
// we just check that it doesn't throw
|
||||
await expect(mount(Parent, fixture, { dev: true })).resolves.toEqual(expect.anything());
|
||||
});
|
||||
|
||||
test("can validate through slots", async () => {
|
||||
class Child extends Component {
|
||||
static props = ["message"];
|
||||
static template = xml`<div>hey</div>`;
|
||||
}
|
||||
|
||||
class Wrapper extends Component {
|
||||
static template = xml`<t t-slot="default"/>`;
|
||||
}
|
||||
|
||||
class Parent extends Component {
|
||||
static components = { Child, Wrapper };
|
||||
static template = xml`<Wrapper><Child /></Wrapper>`;
|
||||
}
|
||||
|
||||
const app = new App(Parent, { test: true });
|
||||
let error: OwlError | undefined;
|
||||
const mountProm = app.mount(fixture).catch((e: Error) => (error = e));
|
||||
await expect(nextAppError(app)).resolves.toThrow(
|
||||
"Invalid props for component 'Child': 'message' is missing"
|
||||
);
|
||||
await mountProm;
|
||||
expect(error!).toBeDefined();
|
||||
expect(error!.message).toBe("Invalid props for component 'Child': 'message' is missing");
|
||||
});
|
||||
});
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user