Skip to content

Commit

Permalink
refactor(components): [link] use JSX in Unit test (element-plus#8140)
Browse files Browse the repository at this point in the history
  • Loading branch information
logustra authored Jun 7, 2022
1 parent db0b4d4 commit b34ca0f
Showing 1 changed file with 17 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,36 @@ const AXIOM = 'Rem is the best girl'

describe('Link.vue', () => {
it('render test', () => {
const wrapper = mount(Link, {
slots: {
default: AXIOM,
},
})
const wrapper = mount(() => <Link>{AXIOM}</Link>)

expect(wrapper.text()).toEqual(AXIOM)
})

it('it should handle click event when link is not disabled', async () => {
const wrapper = mount(Link, {
slots: {
default: AXIOM,
},
})
const wrapper = mount(() => <Link>{AXIOM}</Link>)

await wrapper.find('.el-link').trigger('click')
await wrapper.trigger('click')
expect(wrapper.emitted('click')).toHaveLength(1)
})

it('it should disable click when link is disabled', async () => {
const wrapper = mount(Link, {
slots: {
default: AXIOM,
},
props: {
disabled: true,
},
})

await wrapper.find('.el-link').trigger('click')
expect(wrapper.emitted('click')).toBeUndefined()
const wrapper = mount(() => <Link disabled>{AXIOM}</Link>)

expect(wrapper.classes()).toContain('is-disabled')
expect(wrapper.attributes('href')).toBeUndefined()
})

it('icon slots', () => {
const linkName = 'test link'
const wrapper = mount(Link, {
slots: {
default: linkName,
icon: AXIOM,
},
})

const wrapper = mount(() => (
<Link
v-slots={{
default: () => linkName,
icon: () => AXIOM,
}}
/>
))
expect(wrapper.text()).toContain(linkName)
expect(wrapper.text()).toContain(AXIOM)
})
Expand Down

0 comments on commit b34ca0f

Please sign in to comment.