mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] env: env is now frozen, useSubEnv does not affect user env
This commit is contained in:
@@ -5,6 +5,8 @@ import {
|
||||
useRef,
|
||||
useState,
|
||||
useComponent,
|
||||
useEnv,
|
||||
useSubEnv,
|
||||
onMounted,
|
||||
onPatched,
|
||||
onWillStart,
|
||||
@@ -12,7 +14,7 @@ import {
|
||||
onWillPatch,
|
||||
xml,
|
||||
onWillUnmount,
|
||||
} from "../../src";
|
||||
} from "../../src/index";
|
||||
import { makeTestFixture, nextTick, snapshotEverything } from "../helpers";
|
||||
|
||||
let fixture: HTMLElement;
|
||||
@@ -163,27 +165,30 @@ describe("hooks", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test.skip("can use useEnv", async () => {
|
||||
expect.assertions(2);
|
||||
test("can use useEnv", async () => {
|
||||
expect.assertions(3);
|
||||
class Test extends Component {
|
||||
static template = xml`<div><t t-esc="env.val"/></div>`;
|
||||
setup() {
|
||||
//expect(useEnv()).toBe(this.env);
|
||||
expect(useEnv()).toBe(this.env);
|
||||
}
|
||||
}
|
||||
await mount(Test, fixture);
|
||||
const env = { val: 1 };
|
||||
await new App(Test).configure({ env }).mount(fixture);
|
||||
expect(fixture.innerHTML).toBe("<div>1</div>");
|
||||
});
|
||||
|
||||
test.skip("can use sub env", async () => {
|
||||
test("use sub env does not pollute user env", async () => {
|
||||
class Test extends Component {
|
||||
static template = xml`<div><t t-esc="env.val"/></div>`;
|
||||
setup() {
|
||||
//useSubEnv({ val: 3 });
|
||||
useSubEnv({ val2: 1 });
|
||||
}
|
||||
}
|
||||
const component = await mount(Test, fixture);
|
||||
const env = { val: 3 };
|
||||
const component = await new App(Test).configure({ env }).mount(fixture);
|
||||
expect(fixture.innerHTML).toBe("<div>3</div>");
|
||||
expect(component.env).not.toHaveProperty("val");
|
||||
expect(component.env).not.toHaveProperty("val2");
|
||||
expect(component.env).toHaveProperty("val");
|
||||
});
|
||||
|
||||
@@ -198,22 +203,20 @@ describe("hooks", () => {
|
||||
await mount(Test, fixture);
|
||||
});
|
||||
|
||||
test.skip("parent and child env", async () => {
|
||||
test("parent and child env", async () => {
|
||||
class Child extends Component {
|
||||
static template = xml`<div><t t-esc="env.val"/></div>`;
|
||||
super() {
|
||||
//useSubEnv({ val: 5 });
|
||||
}
|
||||
}
|
||||
|
||||
class Parent extends Component {
|
||||
static template = xml`<t t-esc="env.val"/><Child/>`;
|
||||
static components = { Child };
|
||||
setup() {
|
||||
//useSubEnv({ val: 3 });
|
||||
useSubEnv({ val: 5 });
|
||||
}
|
||||
}
|
||||
mount(Parent, fixture);
|
||||
const env = { val: 3 };
|
||||
await new App(Parent).configure({ env }).mount(fixture);
|
||||
expect(fixture.innerHTML).toBe("3<div>5</div>");
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user