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, + }) + }) +})