mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] bind lifecycle callbacks to component
Before this commit, some of the callbacks were bound to the component and some were not. This commit makes all the callbacks bind to the component.
This commit is contained in:
committed by
Aaron Bohy
parent
82c7c24438
commit
cccb379377
@@ -5,10 +5,13 @@ import {
|
||||
onPatched,
|
||||
onWillUpdateProps,
|
||||
onWillRender,
|
||||
onWillDestroy,
|
||||
onRendered,
|
||||
} from "../../src/component/lifecycle_hooks";
|
||||
import { status } from "../../src/component/status";
|
||||
import {
|
||||
elem,
|
||||
logStep,
|
||||
makeDeferred,
|
||||
makeTestFixture,
|
||||
nextTick,
|
||||
@@ -1196,4 +1199,58 @@ describe("lifecycle hooks", () => {
|
||||
expect(["Parent:willPatch", "Parent:patched"]).toBeLogged();
|
||||
expect(fixture.innerHTML).toBe("<span>Patched</span>");
|
||||
});
|
||||
|
||||
test("lifecycle callbacks are bound to component", async () => {
|
||||
expect.assertions(14);
|
||||
let instance: any;
|
||||
|
||||
class Test extends Component {
|
||||
static template = xml`<t t-esc="props.rev" />`;
|
||||
setup() {
|
||||
instance = this;
|
||||
onWillStart(this.logger("onWillStart"));
|
||||
onMounted(this.logger("onMounted"));
|
||||
onWillUpdateProps(this.logger("onWillUpdateProps"));
|
||||
onWillPatch(this.logger("onWillPatch"));
|
||||
onPatched(this.logger("onPatched"));
|
||||
onWillUnmount(this.logger("onWillUnmount"));
|
||||
onWillDestroy(this.logger("onWillDestroy"));
|
||||
onWillRender(this.logger("onWillRender"));
|
||||
onRendered(this.logger("onRendered"));
|
||||
}
|
||||
logger(hookName: string) {
|
||||
return function (this: Test) {
|
||||
logStep(hookName);
|
||||
expect(this === instance).toBe(true);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class Parent extends Component {
|
||||
static template = xml`<Test rev="rev" />`;
|
||||
static components = { Test };
|
||||
rev = 0;
|
||||
}
|
||||
|
||||
const app = new App(Parent);
|
||||
const comp = await app.mount(fixture);
|
||||
comp.rev++;
|
||||
comp.render();
|
||||
await nextTick();
|
||||
app.destroy();
|
||||
|
||||
expect([
|
||||
"onWillStart",
|
||||
"onWillRender",
|
||||
"onRendered",
|
||||
"onMounted",
|
||||
"onWillUpdateProps",
|
||||
"onWillRender",
|
||||
"onRendered",
|
||||
"onWillPatch",
|
||||
"onPatched",
|
||||
"onWillUnmount",
|
||||
"onWillDestroy",
|
||||
]).toBeLogged();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user