test: added test file

This commit is contained in:
Paul Valerie GOMA 2025-07-31 11:09:12 +02:00
parent e4915e618b
commit 184417f484

34
test/VuseAlert.spec.ts Normal file
View File

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