ni/src/components/button/__tests__/Button.test.ts
HeXiaoLong:Suanier 49de4589bd feat: 搭建UI组件库
1. 完成展示example
2. 按需加载
3. 导入导出
未来:
1. 更多组件
2. 暗黑模式
3. 配置文件
2025-05-20 12:37:09 +08:00

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