[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:
Géry Debongnie
2021-12-21 16:26:29 +01:00
committed by Aaron Bohy
parent aad6b806ba
commit 3c98ef8cb1
3 changed files with 55 additions and 0 deletions
+33
View File
@@ -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 };