import { fireEvent, render, waitFor } from "@testing-library/vue"; import { describe, expect, it } from "vitest"; import DsDialog from "../src/components/overlays/DsDialog.vue"; describe("DsDialog", () => { it("opens modally, has an accessible name and handles Escape cancellation", async () => { const view = render(DsDialog, { props: { modelValue: true, title: "Editar perfil", description: "Actualiza tus datos.", }, slots: { default: "Contenido" }, }); const dialog = view.getByRole("dialog", { hidden: true, }) as HTMLDialogElement; await waitFor(() => expect(dialog.open || dialog.hasAttribute("open")).toBe(true), ); expect(view.getByRole("dialog", { name: "Editar perfil" })).toBe(dialog); await fireEvent(dialog, new Event("cancel", { cancelable: true })); expect(view.emitted()["update:modelValue"]?.at(-1)).toEqual([false]); expect(view.emitted().cancel).toHaveLength(1); }); });