primevue-mirror/components/lib/chip/Chip.spec.js

49 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-09-06 12:03:37 +00:00
import { mount } from '@vue/test-utils';
import Chip from './Chip.vue';
describe('Chip.vue', () => {
let wrapper;
beforeEach(() => {
wrapper = mount(Chip, {
props: {
label: 'PrimeVue',
icon: 'pi pi-primevue',
removable: true
}
});
});
2022-09-14 11:26:01 +00:00
2023-01-06 12:57:00 +00:00
afterEach(() => {
vi.restoreAllMocks();
});
2022-09-06 12:03:37 +00:00
it('should exists', () => {
expect(wrapper.find('.p-chip.p-component').exists()).toBe(true);
expect(wrapper.find('.p-chip-icon').classes()).toContain('pi-primevue');
expect(wrapper.find('.p-chip-text').text()).toBe('PrimeVue');
expect(wrapper.find('.p-chip-remove-icon').exists()).toBe(true);
});
it('should close icon work', async () => {
2022-09-14 11:26:01 +00:00
await wrapper.find('.p-chip-remove-icon').trigger('click');
2022-09-06 12:03:37 +00:00
expect(wrapper.find('.p-chip.p-component').exists()).toBe(false);
});
2023-01-06 12:57:00 +00:00
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();
});
2022-09-14 11:26:01 +00:00
});