mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] portal: do not crash in dev mode
Before this commit, the props validation would fail in dev mode because it did not expect a slot prop.
This commit is contained in:
committed by
Mathieu Duckerts-Antoine
parent
0b1c4dd4ef
commit
4542171a31
@@ -57,6 +57,7 @@ export class Portal extends Component {
|
||||
target: {
|
||||
type: String,
|
||||
},
|
||||
slots: true,
|
||||
};
|
||||
|
||||
constructor(props: any, env: any, node: ComponentNode) {
|
||||
|
||||
@@ -67,6 +67,27 @@ exports[`Portal basic use of portal 1`] = `
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`Portal basic use of portal in dev mode 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
let { text, createBlock, list, multi, html, toggler, component, comment } = bdom;
|
||||
|
||||
let block1 = createBlock(\`<div><span>1</span><block-child-0/></div>\`);
|
||||
let block2 = createBlock(\`<p>2</p>\`);
|
||||
|
||||
function slot1(ctx, node, key = \\"\\") {
|
||||
return block2();
|
||||
}
|
||||
|
||||
return function template(ctx, node, key = \\"\\") {
|
||||
const props2 = {target: '#outside',slots: {'default': {__render: slot1, __ctx: ctx}}}
|
||||
helpers.validateProps(\`Portal\`, props2, ctx)
|
||||
let b3 = component(\`Portal\`, props2, key + \`__3\`, node, ctx);
|
||||
return block1([], [b3]);
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`Portal conditional use of Portal (with sub Component) 1`] = `
|
||||
"function anonymous(bdom, helpers
|
||||
) {
|
||||
|
||||
@@ -10,10 +10,12 @@ import {
|
||||
} from "../../src";
|
||||
import { Portal, xml } from "../../src/";
|
||||
import { elem, makeTestFixture, nextTick, snapshotEverything } from "../helpers";
|
||||
import { DEV_MSG } from "../../src/app/app";
|
||||
|
||||
let fixture: HTMLElement;
|
||||
let originalconsoleWarn = console.warn;
|
||||
let mockConsoleWarn: any;
|
||||
const info = console.info;
|
||||
|
||||
function addOutsideDiv(fixture: HTMLElement): HTMLElement {
|
||||
let outside = document.createElement("div");
|
||||
@@ -24,6 +26,19 @@ function addOutsideDiv(fixture: HTMLElement): HTMLElement {
|
||||
|
||||
snapshotEverything();
|
||||
|
||||
beforeAll(() => {
|
||||
console.info = (message: any) => {
|
||||
if (message === DEV_MSG) {
|
||||
return;
|
||||
}
|
||||
info(message);
|
||||
};
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
console.info = info;
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = makeTestFixture();
|
||||
mockConsoleWarn = jest.fn(() => {});
|
||||
@@ -53,6 +68,24 @@ describe("Portal", () => {
|
||||
expect(fixture.innerHTML).toBe('<div id="outside"><p>2</p></div><div><span>1</span></div>');
|
||||
});
|
||||
|
||||
test("basic use of portal in dev mode", async () => {
|
||||
class Parent extends Component {
|
||||
static components = { Portal };
|
||||
static template = xml`
|
||||
<div>
|
||||
<span>1</span>
|
||||
<Portal target="'#outside'">
|
||||
<p>2</p>
|
||||
</Portal>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
addOutsideDiv(fixture);
|
||||
await mount(Parent, fixture, { dev: true });
|
||||
|
||||
expect(fixture.innerHTML).toBe('<div id="outside"><p>2</p></div><div><span>1</span></div>');
|
||||
});
|
||||
|
||||
test("conditional use of Portal", async () => {
|
||||
class Parent extends Component {
|
||||
static components = { Portal };
|
||||
|
||||
Reference in New Issue
Block a user