test: Added disabled props test

This commit is contained in:
Paul Valerie GOMA 2025-07-19 15:42:14 +02:00
parent e8f1d33441
commit 4b3804ca05

View File

@ -1,6 +1,6 @@
import { mount } from '@vue/test-utils'
import VButton from '@/components/button/VButton.vue'
import {test, expect, describe} from 'vitest'
import {test, expect, describe, vi} from 'vitest'
describe('VButton', () => {
test('Displays button label', () => {
@ -72,4 +72,24 @@ describe('VButton', () => {
expect(iconRight.exists()).toBe(true)
expect(iconRight.classes()).not.toContain('p-button-icon-left')
})
test('Disabled button', async () => {
const onClick = vi.fn()
const wrapper = mount(VButton, {
props: {
title: 'button',
label: 'label',
disabled: true,
onClick,
}
})
const button = wrapper.find('button')
await button.trigger('click')
// check disabled props is set
expect(button.attributes('disabled')).toBeDefined()
// check aria-disabled atribute is set
expect(button.attributes('aria-disabled')).toBe('true')
// check that the onClck function hasn't been called
expect(onClick).not.toHaveBeenCalled()
})
})