primevue-mirror/components/message/Message.spec.js

74 lines
1.8 KiB
JavaScript
Raw Normal View History

2022-12-08 11:04:25 +00:00
import { config, mount } from '@vue/test-utils';
import PrimeVue from 'primevue/config';
2022-09-06 12:03:37 +00:00
import Message from './Message.vue';
2022-12-08 11:04:25 +00:00
config.global.mocks = {
$primevue: {
config: {
locale: {
aria: {
close: 'Close'
}
}
}
}
};
2022-09-06 12:03:37 +00:00
describe('Message.vue', () => {
let wrapper;
beforeEach(() => {
wrapper = mount(Message, {
props: {
severity: 'error'
},
slots: {
default: 'Error Message Content'
}
});
});
it('should exist', () => {
expect(wrapper.find('.p-message.p-component').exists()).toBe(true);
expect(wrapper.find('.p-message.p-component').classes()).toContain('p-message-error');
expect(wrapper.find('.p-message-text').text()).toContain('Error Message Content');
});
it('should close the message', async () => {
await wrapper.vm.close({});
expect(wrapper.vm.visible).toBe(false);
expect(wrapper.emitted().close[0]).toEqual([{}]);
});
2022-12-08 11:04:25 +00:00
it('should have custom close icon if provided', async () => {
await wrapper.setProps({ closeIcon: 'pi pi-discord' });
const icon = wrapper.find('.p-message-close-icon');
expect(icon.classes()).toContain('pi-discord');
});
2022-09-06 12:03:37 +00:00
});
describe('Message.vue', () => {
let wrapper;
beforeEach(() => {
wrapper = mount(Message, {
2022-12-08 11:04:25 +00:00
plugins: [PrimeVue],
2022-09-06 12:03:37 +00:00
props: {
severity: 'error',
life: 3000,
sticky: false
},
slots: {
default: 'Error Message Content'
}
});
});
it('should sticky and life works', async () => {
2022-12-08 11:04:25 +00:00
jest.runTimersToTime(3001);
expect(wrapper.vm.visible).toBe(false);
2022-09-06 12:03:37 +00:00
});
2022-09-14 11:26:01 +00:00
});