[FIX] connected child components with custom hooks

This commit is contained in:
Alexandre Kühn
2019-03-29 17:37:40 +01:00
committed by Géry Debongnie
parent d6e61c2203
commit e7a4ad99de
2 changed files with 50 additions and 0 deletions
+48
View File
@@ -106,4 +106,52 @@ describe("connecting a component to store", () => {
await nextTick();
expect(fixture.innerHTML).toMatchSnapshot();
});
test("connected child components with custom hooks", async () => {
let steps: any = [];
class Child extends Component<any, any, any> {
inlineTemplate = `<div/>`;
mounted() {
steps.push('child:mounted');
}
willUnmount() {
steps.push('child:willUnmount')
}
destroyed() {
steps.push('child:destroyed');
}
}
const ConnectedChild = connect(s => s)(Child);
class Parent extends Component<any, any, any> {
inlineTemplate = `
<div>
<t t-if="state.child" t-widget="ConnectedChild"/>
</div>`;
widgets = { ConnectedChild };
constructor(env: Env) {
super(env);
this.state = { child: true };
}
}
const store = new Store({ state: {} });
(<any>env).store = store;
const parent = new Parent(env);
await parent.mount(fixture);
expect(steps).toEqual([
'child:mounted',
]);
await parent.updateState({ child: false });
expect(steps).toEqual([
'child:mounted',
'child:willUnmount',
'child:destroyed',
]);
});
});