✅ test: added test file
This commit is contained in:
parent
e4915e618b
commit
184417f484
34
test/VuseAlert.spec.ts
Normal file
34
test/VuseAlert.spec.ts
Normal 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,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user