PrimaryButton.test.js 962 Bytes
/**
 * 组件测试示例
 */

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