import { describe, it, expect, beforeEach } from "vitest";
import { App } from "../src/index";
import { RouterPlugin } from "../src/plugins/router";
describe("RouterPlugin", () => {
let app: App;
let router: RouterPlugin;
beforeEach(() => {
app = new App();
router = new RouterPlugin([
{
path: "/",
component: { template: "
Home
" },
},
{
path: "/about",
component: { template: "About
" },
},
]);
app.use(router);
});
it("should render the correct component on route change", () => {
const root = document.createElement("div");
root.innerHTML = "";
document.body.appendChild(root);
router.compile(root.firstElementChild as Element);
router.doRouteChange("/");
expect(root.innerHTML).toContain("Home
");
router.doRouteChange("/about");
expect(root.innerHTML).toContain("About
");
});
});