43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import { afterEach, expect, it, vi } from "vitest";
|
|
import { mount, flushPromises } from "@vue/test-utils";
|
|
import { defineComponent, h, nextTick } from "vue";
|
|
|
|
const demos = import.meta.glob(
|
|
"../apps/docs/demos/{alert-dialog,drawer}-*.vue",
|
|
);
|
|
const wrappers: ReturnType<typeof mount>[] = [];
|
|
afterEach(async () => {
|
|
wrappers.splice(0).forEach((w) => w.unmount());
|
|
await flushPromises();
|
|
vi.restoreAllMocks();
|
|
document.body.innerHTML = "";
|
|
});
|
|
it("all 23 overlay demos coexist in one Vue app without duplicate IDs or warnings", async () => {
|
|
const entries = await Promise.all(
|
|
Object.values(demos).map(
|
|
async (load) =>
|
|
((await load()) as { default: Parameters<typeof h>[0] }).default,
|
|
),
|
|
);
|
|
expect(entries).toHaveLength(23);
|
|
const warnings = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
const wrapper = mount(
|
|
defineComponent({
|
|
render: () =>
|
|
h(
|
|
"main",
|
|
entries.map((demo, i) => h("section", { "data-demo": i }, [h(demo)])),
|
|
),
|
|
}),
|
|
{ attachTo: document.body },
|
|
);
|
|
wrappers.push(wrapper);
|
|
await flushPromises();
|
|
await nextTick();
|
|
expect(wrapper.findAll("section[data-demo]")).toHaveLength(23);
|
|
expect(wrapper.findAll("button").length).toBeGreaterThan(23);
|
|
const ids = [...document.querySelectorAll("[id]")].map((el) => el.id);
|
|
expect(new Set(ids).size).toBe(ids.length);
|
|
expect(warnings).not.toHaveBeenCalled();
|
|
});
|