Skip to content

Commit

Permalink
Merge pull request #484 from w2xi/test-components/dropdown-item
Browse files Browse the repository at this point in the history
test(components): [dropdown-item] cover remaining props
  • Loading branch information
Tyh2001 authored May 7, 2024
2 parents 11c4505 + c4120b2 commit ed412e2
Showing 1 changed file with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,68 @@ describe('DropdownItem', () => {
})

test('disabled', () => {
const fn = vi.fn()
const wrapper = mount(FDropdownItem, {
props: { disabled: true }
props: {
disabled: true,
onClick: () => {
fn('onClick')
}
},
global: {
provide: {
[TRIGGER_CLOSE_KEY as symbol]: {
close: () => {
fn('close')
}
}
}
}
})
expect(wrapper.classes()).toContain('f-dropdown-item__disabled')

wrapper.trigger('click')
expect(fn.mock.calls[0]).not.toEqual(['close'])
expect(fn.mock.calls[1]).not.toEqual(['onClick'])
})

test('onClick', async () => {
const fn = vi.fn()
const wrapper = mount(FDropdownItem, {
props: {
onClick: () => {
onClick() {
fn('onClick')
}
},
})
wrapper.trigger('click')
expect(fn.mock.calls[0]).toEqual(['onClick'])
})

test('close callback should be triggered', async () => {
const fn = vi.fn()
const wrapper = mount(FDropdownItem, {
global: {
provide: {
[TRIGGER_CLOSE_KEY as symbol]: {
close: () => {
close() {
fn('close')
}
}
}
}
})
wrapper.trigger('click')
expect(fn.mock.calls[0][0]).toBe('close')
expect(fn.mock.calls[1][0]).toBe('onClick')
expect(fn.mock.calls[0]).toEqual(['close'])
})

test('should render slot', () => {
const watermelon = '🍉🍉🍉'
const wrapper = mount(FDropdownItem, {
slots: {
default: watermelon
}
})
expect(wrapper.text()).toContain(watermelon)
})
})

0 comments on commit ed412e2

Please sign in to comment.