|
| 1 | +import { h } from '@stencil/core'; |
| 2 | +import { render } from '@wdio/browser-runner/stencil'; |
| 3 | + |
| 4 | +describe('slot-fallback-with-forwarded-slot', () => { |
| 5 | + it('renders fallback via prop', async () => { |
| 6 | + // @ts-expect-error - wdio complaining about missing prop |
| 7 | + const { $root, root } = render({ |
| 8 | + template: () => <slot-forward-root label="Slot fallback via property"></slot-forward-root>, |
| 9 | + }); |
| 10 | + await $root.$('slot-fb'); |
| 11 | + const fb: HTMLElement = document.querySelector('slot-fb'); |
| 12 | + |
| 13 | + expect(await $root.getText()).toBe(''); |
| 14 | + expect(fb.textContent).toBe('Slot fallback via property'); |
| 15 | + expect(fb.getAttribute('hidden')).toBe(null); |
| 16 | + expect(fb.hidden).toBe(false); |
| 17 | + |
| 18 | + const p = document.createElement('p'); |
| 19 | + p.textContent = 'Slot content via slot'; |
| 20 | + p.slot = 'label'; |
| 21 | + root.appendChild(p); |
| 22 | + |
| 23 | + expect(await $root.getText()).toBe('Slot content via slot'); |
| 24 | + expect(fb.getAttribute('hidden')).toBe(''); |
| 25 | + expect(fb.hidden).toBe(true); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should hide slot-fb elements when slotted content exists', async () => { |
| 29 | + // @ts-expect-error - wdio complaining about missing prop |
| 30 | + const { $root, root } = render({ |
| 31 | + template: () => ( |
| 32 | + <slot-forward-root label="Slot fallback via property"> |
| 33 | + <div slot="label">Slot content via slot</div> |
| 34 | + </slot-forward-root> |
| 35 | + ), |
| 36 | + }); |
| 37 | + await $root.$('slot-fb'); |
| 38 | + const fb: HTMLElement = document.querySelector('slot-fb'); |
| 39 | + |
| 40 | + expect(await $root.getText()).toBe('Slot content via slot'); |
| 41 | + expect(fb.textContent).toBe('Slot fallback via property'); |
| 42 | + expect(fb.getAttribute('hidden')).toBe(''); |
| 43 | + expect(fb.hidden).toBe(true); |
| 44 | + |
| 45 | + root.removeChild(root.childNodes[0]); |
| 46 | + |
| 47 | + expect(await $root.getText()).toBe(''); |
| 48 | + expect(fb.getAttribute('hidden')).toBe(null); |
| 49 | + expect(fb.hidden).toBe(false); |
| 50 | + }); |
| 51 | +}); |
0 commit comments