imp: add willUpdateProps hook to components

This commit is contained in:
Géry Debongnie
2019-04-09 13:51:04 +02:00
parent 816ffe1b44
commit bc07c49a5f
3 changed files with 48 additions and 9 deletions
+21
View File
@@ -387,6 +387,27 @@ describe("lifecycle hooks", () => {
]);
});
test("willUpdateProps hook is called", async () => {
let def = makeDeferred();
class HookWidget extends Widget {
inlineTemplate = '<span><t t-esc="props.n"/></span>';
willUpdateProps(nextProps) {
expect(nextProps.n).toBe(2);
return def;
}
}
const widget = new HookWidget(env, { n: 1 });
await widget.mount(fixture);
expect(fixture.innerHTML).toBe("<span>1</span>");
widget.updateProps({ n: 2 });
await nextTick();
expect(fixture.innerHTML).toBe("<span>1</span>");
def.resolve();
await nextTick();
expect(fixture.innerHTML).toBe("<span>2</span>");
});
test("patched hook is called after updateState", async () => {
let n = 0;