mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] hooks: add some building blocks for hooks
This commit introduces two new hooks: useComponent, and useEnv.
This commit is contained in:
@@ -9,8 +9,10 @@ import {
|
||||
onWillPatch,
|
||||
onWillStart,
|
||||
onWillUpdateProps,
|
||||
useEnv,
|
||||
useSubEnv,
|
||||
useExternalListener,
|
||||
useComponent,
|
||||
} from "../src/hooks";
|
||||
import { xml } from "../src/tags";
|
||||
|
||||
@@ -520,6 +522,19 @@ describe("hooks", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("can use useEnv", async () => {
|
||||
expect.assertions(1);
|
||||
class TestComponent extends Component {
|
||||
static template = xml`<div><t t-esc="env.val"/></div>`;
|
||||
constructor() {
|
||||
super();
|
||||
expect(useEnv()).toBe(env);
|
||||
}
|
||||
}
|
||||
const component = new TestComponent();
|
||||
await component.mount(fixture);
|
||||
});
|
||||
|
||||
test("can use sub env", async () => {
|
||||
class TestComponent extends Component {
|
||||
static template = xml`<div><t t-esc="env.val"/></div>`;
|
||||
@@ -535,6 +550,19 @@ describe("hooks", () => {
|
||||
expect(component.env).toHaveProperty("val");
|
||||
});
|
||||
|
||||
test("can use useComponent", async () => {
|
||||
expect.assertions(1);
|
||||
class TestComponent extends Component {
|
||||
static template = xml`<div></div>`;
|
||||
constructor() {
|
||||
super();
|
||||
expect(useComponent()).toBe(this);
|
||||
}
|
||||
}
|
||||
const component = new TestComponent();
|
||||
await component.mount(fixture);
|
||||
});
|
||||
|
||||
test("parent and child env", async () => {
|
||||
class Child extends Component {
|
||||
static template = xml`<div><t t-esc="env.val"/></div>`;
|
||||
|
||||
Reference in New Issue
Block a user