35 lines
790 B
TypeScript
35 lines
790 B
TypeScript
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,
|
||
})
|
||
})
|
||
})
|