58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { mount } from '@vue/test-utils'
|
|
import Button from '../Button.vue'
|
|
|
|
describe('Button.vue', () => {
|
|
it('renders slot content', () => {
|
|
const wrapper = mount(Button, {
|
|
slots: {
|
|
default: '按钮文本'
|
|
}
|
|
})
|
|
expect(wrapper.text()).toBe('按钮文本')
|
|
})
|
|
|
|
it('applies type class', () => {
|
|
const wrapper = mount(Button, {
|
|
props: {
|
|
type: 'primary'
|
|
}
|
|
})
|
|
expect(wrapper.classes()).toContain('ni-button--primary')
|
|
})
|
|
|
|
it('applies size class', () => {
|
|
const wrapper = mount(Button, {
|
|
props: {
|
|
size: 'small'
|
|
}
|
|
})
|
|
expect(wrapper.classes()).toContain('ni-button--small')
|
|
})
|
|
|
|
it('applies disabled class and attribute', () => {
|
|
const wrapper = mount(Button, {
|
|
props: {
|
|
disabled: true
|
|
}
|
|
})
|
|
expect(wrapper.classes()).toContain('is-disabled')
|
|
expect(wrapper.attributes('disabled')).toBeDefined()
|
|
})
|
|
|
|
it('emits click event when clicked', async () => {
|
|
const wrapper = mount(Button)
|
|
await wrapper.trigger('click')
|
|
expect(wrapper.emitted('click')).toBeTruthy()
|
|
})
|
|
|
|
it('does not emit click event when disabled', async () => {
|
|
const wrapper = mount(Button, {
|
|
props: {
|
|
disabled: true
|
|
}
|
|
})
|
|
await wrapper.trigger('click')
|
|
expect(wrapper.emitted('click')).toBeFalsy()
|
|
})
|
|
})
|