PrimaryButton.test.js
962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* 组件测试示例
*/
import { describe, it, expect } from 'vitest'
import { mount } from '@vue/test-utils'
import PrimaryButton from '@/components/PrimaryButton.vue'
describe('PrimaryButton', () => {
it('should render button with text', () => {
const wrapper = mount(PrimaryButton, {
props: {
text: '点击按钮',
},
})
expect(wrapper.text()).toContain('点击按钮')
})
it('should emit click event when clicked', async () => {
const wrapper = mount(PrimaryButton, {
props: {
text: '点击',
},
})
await wrapper.trigger('click')
expect(wrapper.emitted('click')).toBeTruthy()
})
it('should be disabled when disabled prop is true', () => {
const wrapper = mount(PrimaryButton, {
props: {
text: '点击',
disabled: true,
},
})
const button = wrapper.find('button')
expect(button.attributes('disabled')).toBeDefined()
})
})