link.test.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { mount } from '@vue/test-utils'
  2. import { describe, expect, it } from 'vitest'
  3. import Link from '../src/link.vue'
  4. const AXIOM = 'Rem is the best girl'
  5. describe('Link.vue', () => {
  6. it('render test', () => {
  7. const wrapper = mount(() => <Link>{AXIOM}</Link>)
  8. expect(wrapper.text()).toEqual(AXIOM)
  9. })
  10. it('it should handle click event when link is not disabled', async () => {
  11. const wrapper = mount(() => <Link>{AXIOM}</Link>)
  12. await wrapper.trigger('click')
  13. expect(wrapper.emitted('click')).toHaveLength(1)
  14. })
  15. it('it should disable click when link is disabled', async () => {
  16. const wrapper = mount(() => <Link disabled>{AXIOM}</Link>)
  17. expect(wrapper.classes()).toContain('is-disabled')
  18. expect(wrapper.attributes('href')).toBeUndefined()
  19. })
  20. it('icon slots', () => {
  21. const linkName = 'test link'
  22. const wrapper = mount(() => (
  23. <Link
  24. v-slots={{
  25. default: () => linkName,
  26. icon: () => AXIOM,
  27. }}
  28. />
  29. ))
  30. expect(wrapper.text()).toContain(linkName)
  31. expect(wrapper.text()).toContain(AXIOM)
  32. })
  33. })