Create ToggleButton.spec.js

pull/2660/head
Tuğçe Küçükoğlu 2022-06-13 13:01:20 +03:00
parent 7d386882dc
commit 130967049f
1 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,54 @@
import { mount } from '@vue/test-utils';
import ToggleButton from './ToggleButton.vue';
describe('ToggleButton', () => {
let wrapper;
beforeEach(() => {
wrapper = mount(ToggleButton, {
props: {
modelValue: false,
onIcon: 'pi pi-check',
offIcon: 'pi pi-times'
}
});
});
it('is ToggleButton exist', () => {
expect(wrapper.find('.p-togglebutton.p-component').exists()).toBe(true);
expect(wrapper.find('span.pi-times.p-button-icon').exists()).toBe(true);
});
it('should have onIcon', async () => {
await wrapper.setProps({ modelValue: true });
expect(wrapper.find('span.pi-check').exists()).toBe(true);
});
it('should click works', async () => {
await wrapper.vm.onClick({});
expect(wrapper.emitted()['update:modelValue'][0]).toEqual([true]);
await wrapper.setProps({ modelValue: true });
await wrapper.vm.onClick({});
expect(wrapper.emitted()['update:modelValue'][1]).toEqual([false]);
});
it('should be customized', async () => {
await wrapper.setProps({
modelValue: true,
onLabel: 'I confirm',
offLabel: 'I reject',
style: 'width: 10em'
});
expect(wrapper.find('.p-button-label').text()).toBe('I confirm');
expect(wrapper.attributes().style).toContain('width: 10em');
await wrapper.setProps({ modelValue: false });
expect(wrapper.find('.p-button-label').text()).toBe('I reject');
});
});