mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
address PR comments
This commit is contained in:
committed by
Herrington Darkholme
parent
2930afa650
commit
2aa90a4fa8
@@ -13,29 +13,23 @@ describe('Link.vue', () => {
|
||||
expect(wrapper.text()).toEqual(AXIOM)
|
||||
})
|
||||
|
||||
test('it should handle click event when href were given and is not disabled', async () => {
|
||||
const href = 'https://target.com'
|
||||
test('it should handle click event when link is not disabled', async () => {
|
||||
const wrapper = mount(Link, {
|
||||
slots: {
|
||||
default: AXIOM,
|
||||
},
|
||||
props: {
|
||||
href,
|
||||
},
|
||||
})
|
||||
|
||||
await wrapper.find('.el-link').trigger('click')
|
||||
expect(wrapper.emitted('click')).toHaveLength(1)
|
||||
})
|
||||
|
||||
test('it should disable click when it\'s disabled', async () => {
|
||||
const href = 'https://target.com'
|
||||
test('it should disable click when link is disabled', async () => {
|
||||
const wrapper = mount(Link, {
|
||||
slots: {
|
||||
default: AXIOM,
|
||||
},
|
||||
props: {
|
||||
href,
|
||||
disabled: true,
|
||||
},
|
||||
})
|
||||
@@ -45,5 +39,16 @@ describe('Link.vue', () => {
|
||||
})
|
||||
|
||||
|
||||
test('icon slots', () => {
|
||||
const linkName = 'test link'
|
||||
const wrapper = mount(Link, {
|
||||
slots: {
|
||||
default: linkName,
|
||||
icon: AXIOM,
|
||||
},
|
||||
})
|
||||
expect(wrapper.text()).toContain(linkName)
|
||||
expect(wrapper.text()).toContain(AXIOM)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
@@ -16,19 +16,19 @@
|
||||
<slot></slot>
|
||||
</span>
|
||||
|
||||
<template v-if="$slots.icon">
|
||||
<slot v-if="$slots.icon" name="icon"></slot>
|
||||
</template>
|
||||
<slot v-if="$slots.icon" name="icon"></slot>
|
||||
</a>
|
||||
</template>
|
||||
<script lang='ts'>
|
||||
import { defineComponent } from 'vue'
|
||||
import { defineComponent, PropType } from 'vue'
|
||||
|
||||
type ILinkType = PropType<'primary' | 'success' | 'warning' | 'info' | 'error' | ''>
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ElLink',
|
||||
props: {
|
||||
type: {
|
||||
type: String,
|
||||
type: String as ILinkType,
|
||||
default: '',
|
||||
validator: (val: string) => {
|
||||
return ['', 'primary', 'success', 'warning', 'info', 'error'].includes(val)
|
||||
@@ -46,7 +46,7 @@ export default defineComponent({
|
||||
setup(props, { emit }) {
|
||||
|
||||
function handleClick(event: Event) {
|
||||
if (!props.disabled && !!props.href) {
|
||||
if (!props.disabled) {
|
||||
emit('click', event)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user