diff --git a/components/chip/Chip.spec.js b/components/chip/Chip.spec.js index 47e1fe62b..e09d6729e 100644 --- a/components/chip/Chip.spec.js +++ b/components/chip/Chip.spec.js @@ -14,6 +14,10 @@ describe('Chip.vue', () => { }); }); + afterEach(() => { + vi.restoreAllMocks(); + }); + it('should exists', () => { expect(wrapper.find('.p-chip.p-component').exists()).toBe(true); expect(wrapper.find('.p-chip-icon').classes()).toContain('pi-primevue'); @@ -26,4 +30,19 @@ describe('Chip.vue', () => { expect(wrapper.find('.p-chip.p-component').exists()).toBe(false); }); + + it('When removable is true and keydown triggered OnKeydown method should be called', async () => { + const closeSpy = vi.spyOn(wrapper.vm, 'onKeydown'); + + await wrapper.find('.p-chip-remove-icon').trigger('keydown'); + + expect(closeSpy).toHaveBeenCalled(); + }); + it('When onKeyDown method triggered close method should be called', async () => { + const closeSpy = vi.spyOn(wrapper.vm, 'close'); + + await wrapper.vm.onKeydown({ key: 'Enter' }); + + expect(closeSpy).toHaveBeenCalled(); + }); });