make sure env is propagated to child widgets

This commit is contained in:
Géry Debongnie
2019-01-26 20:33:23 +01:00
parent 8488c41b38
commit 90f30c6c72
2 changed files with 13 additions and 1 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ export class Widget<T extends WEnv> {
if (parent instanceof Widget) {
p = parent;
parent.__widget__.children.push(this);
this.env = Object.create(parent.env);
this.env = parent.env;
} else {
this.env = parent;
}
+12
View File
@@ -97,6 +97,11 @@ describe("basic widget properties", () => {
await widget.mount(fixture);
expect(renderCalls).toBe(1);
});
test("keep a reference to env", async () => {
const widget = new Widget(env);
expect(widget.env).toBe(env);
});
});
describe("lifecycle hooks", () => {
@@ -324,4 +329,11 @@ describe("composition", () => {
(<any>widget.__widget__.children[0].__widget__.vnode).elm
);
});
test("parent env is propagated to child widgets", async () => {
const widget = new WidgetA(env);
await widget.mount(fixture);
expect(widget.__widget__.children[0].env).toBe(env);
});
});