[FIX] qweb: properly remove t-ref reference

when the node is removed from the dom
This commit is contained in:
Géry Debongnie
2019-10-10 17:08:16 +02:00
committed by aab-odoo
parent 1337aa0107
commit 4a346d0615
5 changed files with 36 additions and 1 deletions
+21
View File
@@ -234,6 +234,27 @@ describe("hooks", () => {
expect(fixture.innerHTML).toBe("<div><button>1</button></div>");
});
test("useRef hook is null if ref is removed ", async () => {
expect.assertions(4);
class TestRef extends Component<any, any> {
static template = xml`<div><span t-if="state.flag" t-ref="span">owl</span></div>`;
spanRef = useRef("span");
state = useState({ flag: true });
willPatch() {
expect(this.spanRef.el).not.toBeNull();
}
patched() {
expect(this.spanRef.el).toBeNull();
}
}
const component = new TestRef(env);
await component.mount(fixture);
expect(fixture.innerHTML).toBe("<div><span>owl</span></div>");
component.state.flag = false;
await nextTick();
expect(fixture.innerHTML).toBe("<div></div>");
});
test("can use onPatched, onWillPatch", async () => {
const steps: string[] = [];
function useMyHook() {