diff --git a/src/components/__tests__/Toaster.spec.tsx b/src/components/__tests__/Toaster.spec.tsx index 0df1eb8..ed13e0d 100644 --- a/src/components/__tests__/Toaster.spec.tsx +++ b/src/components/__tests__/Toaster.spec.tsx @@ -27,11 +27,11 @@ const ToasterTest = ({ toast = "This is a toast!" }: { toast?: Toast }) => { }; beforeAll(() => { - Element.prototype.animate = vi - .fn() - .mockImplementation(() => ({ finished: Promise.resolve() })); - - // Element.prototype.addEventListener = vi.fn().mockImplementation(() => {}); + Element.prototype.animate = vi.fn().mockImplementation(() => ({ + finished: Promise.resolve(), + addEventListener: vi.fn((type: string, callback: () => void) => callback()), + play: vi.fn(), + })) }); afterAll(() => { @@ -58,7 +58,7 @@ const sleep = (ms: number) => { }); }; -test.skip("Toast stays on screen for >= given duration", async () => { +test("Toast stays on screen for >= given duration", async () => { const TOAST_WITH_CUSTOM_DURATION = { duration: 1000, content: "This is my second toast", @@ -77,7 +77,7 @@ test.skip("Toast stays on screen for >= given duration", async () => { await component.findByRole("alert"); - await sleep(TOAST_WITH_CUSTOM_DURATION.duration / 2 + 200); + await sleep(TOAST_WITH_CUSTOM_DURATION.duration / 2); const isThereAToast = component.queryByRole("alert"); expect(isThereAToast).toBeNull(); diff --git a/vite.config.ts b/vite.config.ts index 03f8d13..f410ca3 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,11 +1,17 @@ -/// -import { defineConfig } from "vite"; -import react from "@vitejs/plugin-react"; +import react from '@vitejs/plugin-react'; +import { defineConfig, UserConfig } from 'vite'; +import type { InlineConfig } from 'vitest'; -export default defineConfig({ +interface VitestConfigExport extends UserConfig { + test: InlineConfig; +} + +const vitestConfig: VitestConfigExport = { plugins: [react()], test: { - environment: "jsdom", + environment: 'jsdom', globals: true, }, -}); +}; + +export default defineConfig(vitestConfig); \ No newline at end of file