primevue-mirror/components/chips/Chips.spec.js

45 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-09-06 12:03:37 +00:00
import { mount } from '@vue/test-utils';
import Chips from './Chips.vue';
describe('Chips.vue', () => {
let wrapper;
beforeEach(() => {
wrapper = mount(Chips, {
props: {
modelValue: null
}
});
});
it('should exist', () => {
expect(wrapper.find('.p-chips.p-component.p-inputwrapper').exists()).toBe(true);
expect(wrapper.find('ul.p-chips-multiple-container').exists()).toBe(true);
expect(wrapper.find('li.p-chips-input-token').exists()).toBe(true);
});
2022-09-14 11:26:01 +00:00
it('should add item', async () => {
2022-12-08 14:13:16 +00:00
const addItem = vi.spyOn(wrapper.vm, 'addItem');
2022-09-14 11:26:01 +00:00
await wrapper.vm.addItem({}, 'PrimeVue', false);
2022-09-06 12:03:37 +00:00
await wrapper.setProps({ modelValue: ['PrimeVue'] });
expect(addItem).toHaveBeenCalled();
expect(wrapper.findAll('.p-chips-token').length).toBe(1);
expect(wrapper.find('.p-chips-token-label').exists()).toBe(true);
expect(wrapper.find('.p-chips-token-label').text()).toBe('PrimeVue');
});
2022-12-08 11:04:25 +00:00
it('should have correct custom chip removal icon', async () => {
await wrapper.setProps({
modelValue: ['foo', 'bar'],
removeTokenIcon: 'pi pi-discord'
});
const icon = wrapper.find('.p-chips-token-icon');
expect(icon.classes()).toContain('pi-discord');
});
2022-09-14 11:26:01 +00:00
});