alert.test.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { mount } from '@vue/test-utils'
  2. import { describe, expect, test } from 'vitest'
  3. import { TypeComponentsMap } from '@element-plus/utils'
  4. import Alert from '../src/alert.vue'
  5. const AXIOM = 'Rem is the best girl'
  6. describe('Alert.vue', () => {
  7. test('render test & class', () => {
  8. const wrapper = mount(() => <Alert title={AXIOM} showIcon={true} />)
  9. expect(wrapper.find('.el-alert__title').text()).toEqual(AXIOM)
  10. expect(wrapper.find('.el-alert').classes()).toContain('el-alert--info')
  11. })
  12. test('type', () => {
  13. const wrapper = mount(() => (
  14. <Alert title={'test'} showIcon={true} type={'success'} />
  15. ))
  16. expect(wrapper.find('.el-alert').classes()).toContain('el-alert--success')
  17. expect(wrapper.find('.el-alert__icon').classes()).toContain('el-icon')
  18. expect(wrapper.findComponent(TypeComponentsMap.success).exists()).toBe(true)
  19. })
  20. test('description', () => {
  21. const wrapper = mount(() => (
  22. <Alert title={'Dorne'} showIcon={true} description={AXIOM} />
  23. ))
  24. expect(wrapper.find('.el-alert__description').text()).toEqual(AXIOM)
  25. })
  26. test('theme', () => {
  27. const wrapper = mount(() => <Alert title={'test'} effect={'dark'} />)
  28. expect(wrapper.find('.el-alert').classes()).toContain('is-dark')
  29. })
  30. test('title slot', () => {
  31. const wrapper = mount(() => <Alert title={AXIOM} />)
  32. expect(wrapper.find('.el-alert__title').text()).toEqual(AXIOM)
  33. })
  34. test('close', async () => {
  35. const wrapper = mount(() => <Alert closeText={'close'} />)
  36. const closeBtn = wrapper.find('.el-alert__close-btn')
  37. expect(closeBtn.exists()).toBe(true)
  38. await closeBtn.trigger('click')
  39. expect(wrapper.emitted()).toBeDefined()
  40. })
  41. })