visua-vue/test/VuseAlert.spec.ts
2025-07-31 11:09:12 +02:00

35 lines
790 B
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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