2020-08-04 22:40:00 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
2022-03-25 15:35:56 +08:00
|
|
|
import { describe, expect, it } from 'vitest'
|
2021-09-22 00:48:26 +08:00
|
|
|
import Link from '../src/link.vue'
|
2020-08-04 22:40:00 +08:00
|
|
|
|
|
|
|
const AXIOM = 'Rem is the best girl'
|
|
|
|
|
|
|
|
describe('Link.vue', () => {
|
2022-03-12 17:21:20 +08:00
|
|
|
it('render test', () => {
|
2020-08-04 22:40:00 +08:00
|
|
|
const wrapper = mount(Link, {
|
|
|
|
slots: {
|
|
|
|
default: AXIOM,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
expect(wrapper.text()).toEqual(AXIOM)
|
|
|
|
})
|
|
|
|
|
2022-03-12 17:21:20 +08:00
|
|
|
it('it should handle click event when link is not disabled', async () => {
|
2020-08-04 22:40:00 +08:00
|
|
|
const wrapper = mount(Link, {
|
|
|
|
slots: {
|
|
|
|
default: AXIOM,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
await wrapper.find('.el-link').trigger('click')
|
|
|
|
expect(wrapper.emitted('click')).toHaveLength(1)
|
|
|
|
})
|
|
|
|
|
2022-03-12 17:21:20 +08:00
|
|
|
it('it should disable click when link is disabled', async () => {
|
2020-08-04 22:40:00 +08:00
|
|
|
const wrapper = mount(Link, {
|
|
|
|
slots: {
|
|
|
|
default: AXIOM,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
disabled: true,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
await wrapper.find('.el-link').trigger('click')
|
|
|
|
expect(wrapper.emitted('click')).toBeUndefined()
|
|
|
|
})
|
|
|
|
|
2022-03-12 17:21:20 +08:00
|
|
|
it('icon slots', () => {
|
2020-08-05 14:43:25 +08:00
|
|
|
const linkName = 'test link'
|
|
|
|
const wrapper = mount(Link, {
|
|
|
|
slots: {
|
|
|
|
default: linkName,
|
|
|
|
icon: AXIOM,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
expect(wrapper.text()).toContain(linkName)
|
|
|
|
expect(wrapper.text()).toContain(AXIOM)
|
|
|
|
})
|
2020-08-04 22:40:00 +08:00
|
|
|
})
|