mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] component: validate mounting target at patch time
This commit is contained in:
committed by
Aaron Bohy
parent
bd98d4d0d0
commit
50aac42bdc
@@ -81,6 +81,19 @@ exports[`basics a class component inside a class component, no external dom 2`]
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`basics a component cannot be mounted in a detached node (even if node is detached later 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||
|
||||
let block1 = createBlock(\`<div/>\`);
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
return block1();
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`basics a component inside a component 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
|
||||
@@ -171,6 +171,27 @@ describe("basics", () => {
|
||||
expect(error!.message).toBe("Cannot mount a component on a detached dom node");
|
||||
});
|
||||
|
||||
test("a component cannot be mounted in a detached node (even if node is detached later)", async () => {
|
||||
const warn = console.warn;
|
||||
console.warn = jest.fn();
|
||||
class Test extends Component {
|
||||
static template = xml`<div/>`;
|
||||
}
|
||||
let error: Error;
|
||||
const prom = mount(Test, fixture);
|
||||
await Promise.resolve();
|
||||
fixture.remove();
|
||||
try {
|
||||
await prom;
|
||||
} catch (e) {
|
||||
error = e as Error;
|
||||
}
|
||||
expect(error!).toBeDefined();
|
||||
expect(error!.message).toBe("Cannot mount a component on a detached dom node");
|
||||
expect(console.warn).toBeCalledTimes(1);
|
||||
console.warn = warn;
|
||||
});
|
||||
|
||||
test("crashes if it cannot find a template", async () => {
|
||||
class Test extends Component {
|
||||
static template = "wrongtemplate";
|
||||
|
||||
Reference in New Issue
Block a user