From 184417f484cd3447b2b889c17c6c00ad272c06b1 Mon Sep 17 00:00:00 2001 From: Paul Valerie GOMA Date: Thu, 31 Jul 2025 11:09:12 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20test:=20added=20test=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/VuseAlert.spec.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/VuseAlert.spec.ts diff --git a/test/VuseAlert.spec.ts b/test/VuseAlert.spec.ts new file mode 100644 index 0000000..7ab4c4e --- /dev/null +++ b/test/VuseAlert.spec.ts @@ -0,0 +1,34 @@ +import { describe, it, expect, vi } from 'vitest' + +// 1️⃣ Mock BEFORE importing useAlert +const addSpy = vi.fn() +vi.mock('primevue/usetoast', () => ({ + useToast: () => ({ + add: addSpy + }) +})) + +// 2️⃣ Import le module après que le mock soit actif +import { useAlert } from '../src/components/composable/useAlert' + +describe('useAlert', () => { + it('should call toast.add with correct options', () => { + const { showAlert } = useAlert() + + showAlert({ + title: 'Test title', + description: 'Test description', + type: 'warn', + closeable: true, + lifeTime: 3000, + }) + + expect(addSpy).toHaveBeenCalledWith({ + severity: 'warn', + summary: 'Test title', + detail: 'Test description', + closable: true, + life: 3000, + }) + }) +})