From c4120b283f02f74df4d32af59fb3a4c8017612f1 Mon Sep 17 00:00:00 2001 From: w2xi <43wangxi@gmail.com> Date: Tue, 7 May 2024 21:13:57 +0800 Subject: [PATCH] test(components): [dropdown-item] cover remaining props --- .../__test__/dropdown-item.spec.ts | 46 +++++++++++++++++-- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/packages/fighting-design/dropdown-item/__test__/dropdown-item.spec.ts b/packages/fighting-design/dropdown-item/__test__/dropdown-item.spec.ts index 82dd27cea9..659594959a 100644 --- a/packages/fighting-design/dropdown-item/__test__/dropdown-item.spec.ts +++ b/packages/fighting-design/dropdown-item/__test__/dropdown-item.spec.ts @@ -10,24 +10,51 @@ 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') } } @@ -35,7 +62,16 @@ describe('DropdownItem', () => { } }) 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) }) })