1 | import { mount } from '@vue/test-utils';
|
2 | import { isSlotEmpty } from './is_slot_empty';
|
3 |
|
4 | describe('is slot empty', () => {
|
5 | const TestComponent = {
|
6 | template: `
|
7 | <div>
|
8 | <slot></slot>
|
9 | </div>
|
10 | `,
|
11 | };
|
12 |
|
13 | it('should return true for empty slot', () => {
|
14 | const PassesNothing = {
|
15 | components: { TestComponent },
|
16 | template: '<test-component></test-component>',
|
17 | };
|
18 |
|
19 | const wrapper = mount(PassesNothing);
|
20 |
|
21 | expect(isSlotEmpty(wrapper.findComponent(TestComponent).vm, 'default')).toBe(true);
|
22 | });
|
23 |
|
24 | it('should return true for slot with comment', () => {
|
25 | const PassesComment = {
|
26 | components: { TestComponent },
|
27 | template: '<test-component><!-- comment --></test-component>',
|
28 | };
|
29 |
|
30 | const wrapper = mount(PassesComment);
|
31 |
|
32 | expect(isSlotEmpty(wrapper.findComponent(TestComponent).vm, 'default')).toBe(true);
|
33 | });
|
34 |
|
35 | it('should return true for slot with multiple comments', () => {
|
36 | const PassesComment = {
|
37 | components: { TestComponent },
|
38 | template: '<test-component><!-- comment --><!-- comment2 --></test-component>',
|
39 | };
|
40 |
|
41 | const wrapper = mount(PassesComment);
|
42 |
|
43 | expect(isSlotEmpty(wrapper.findComponent(TestComponent).vm, 'default')).toBe(true);
|
44 | });
|
45 |
|
46 | it('should return false for non-empty slot', () => {
|
47 | const PassesComment = {
|
48 | components: { TestComponent },
|
49 | template: '<test-component>non-empty</test-component>',
|
50 | };
|
51 |
|
52 | const wrapper = mount(PassesComment);
|
53 |
|
54 | expect(isSlotEmpty(wrapper.findComponent(TestComponent).vm, 'default')).toBe(false);
|
55 | });
|
56 |
|
57 | it.each([true, false])(
|
58 | 'should return %s for conditional slot contents based on slot-scope',
|
59 | (shouldRender) => {
|
60 | const PassesComment = {
|
61 | components: { TestComponent },
|
62 | template:
|
63 | '<test-component><template #default="{ shouldRender }"><span v-if="shouldRender">empty</span></template></test-component>',
|
64 | };
|
65 |
|
66 | const wrapper = mount(PassesComment);
|
67 |
|
68 | expect(
|
69 | isSlotEmpty(wrapper.findComponent(TestComponent).vm, 'default', { shouldRender })
|
70 | ).toBe(!shouldRender);
|
71 | }
|
72 | );
|
73 | });
|