primevue-mirror/components/lib/togglebutton/ToggleButton.spec.js

55 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-09-06 12:03:37 +00:00
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 });
2022-09-14 11:26:01 +00:00
2022-09-06 12:03:37 +00:00
expect(wrapper.find('span.pi-check').exists()).toBe(true);
});
it('should change works', async () => {
await wrapper.vm.onChange({});
2022-09-06 12:03:37 +00:00
expect(wrapper.emitted()['update:modelValue'][0]).toEqual([true]);
await wrapper.setProps({ modelValue: true });
await wrapper.vm.onChange({});
2022-09-06 12:03:37 +00:00
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');
});
2022-09-14 11:26:01 +00:00
});