"use strict"; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _react = require('@testing-library/react'); var _runtime = require('@umijs/runtime'); var _react3 = require('react'); var _react4 = _interopRequireDefault(_react3); var _testutils = require('react-dom/test-utils'); var _renderClient = require('./renderClient'); let container; beforeEach(() => { container = document.createElement("div"); container.id = "app"; document.body.appendChild(container); }); afterEach(() => { document.body.removeChild(container); container = null; _react.cleanup.call(void 0, ); }); test("normal", () => { const plugin = new (0, _runtime.Plugin)({ validKeys: ["rootContainer"] }); plugin.register({ apply: { rootContainer(container3, args) { if (!(args.plugin && args.routes)) { throw new Error("history, plugin or routes not exists in the args of rootContainer"); } return /* @__PURE__ */ _react4.default.createElement("div", null, /* @__PURE__ */ _react4.default.createElement("h1", null, "root container"), container3); } }, path: "/foo" }); const routes = [ {path: "/foo", component: () => /* @__PURE__ */ _react4.default.createElement("h1", null, "foo")}, {path: "/bar", component: () => /* @__PURE__ */ _react4.default.createElement("h1", null, "bar")} ]; const {container: container1} = _react.render.call(void 0, _renderClient.renderClient.call(void 0, { plugin, routes, path: "/foo" })); expect(container1.innerHTML).toEqual("

root container

foo

"); window.g_path = "/bar"; const {container: container2} = _react.render.call(void 0, _renderClient.renderClient.call(void 0, { plugin, routes })); expect(container2.innerHTML).toEqual("

root container

bar

"); expect(() => { _renderClient.renderClient.call(void 0, { plugin, routes, path: "/haha" }); }).toThrow(/Render failed, route of path \/haha not found\./); let loading = true; _testutils.act.call(void 0, () => { _renderClient.renderClient.call(void 0, { plugin, routes, rootElement: "app", callback: () => { loading = false; } }); }); expect(loading).toBeFalsy(); }); test("do not support child routes", () => { const plugin = new (0, _runtime.Plugin)({ validKeys: [] }); expect(() => { _renderClient.renderClient.call(void 0, { routes: [{path: "/", routes: []}], plugin }); }).toThrow(/Render failed, child routes is not supported in mpa renderer\./); });