|
| 1 | +/** |
| 2 | + * @jest-environment node |
| 3 | + */ |
| 4 | + |
| 5 | +import { createApp } from 'vue' |
| 6 | +import { renderToString } from '../src/renderToString' |
| 7 | + |
| 8 | +const components = { |
| 9 | + one: { |
| 10 | + template: `<div><slot/></div>` |
| 11 | + } |
| 12 | +} |
| 13 | + |
| 14 | +describe('ssr: slot', () => { |
| 15 | + test('text slot', async () => { |
| 16 | + expect( |
| 17 | + await renderToString( |
| 18 | + createApp({ |
| 19 | + components, |
| 20 | + template: `<one>hello</one>` |
| 21 | + }) |
| 22 | + ) |
| 23 | + ).toBe(`<div><!--[-->hello<!--]--></div>`) |
| 24 | + }) |
| 25 | + |
| 26 | + test('element slot', async () => { |
| 27 | + expect( |
| 28 | + await renderToString( |
| 29 | + createApp({ |
| 30 | + components, |
| 31 | + template: `<one><div>hi</div></one>` |
| 32 | + }) |
| 33 | + ) |
| 34 | + ).toBe(`<div><!--[--><div>hi</div><!--]--></div>`) |
| 35 | + }) |
| 36 | + |
| 37 | + test('empty slot', async () => { |
| 38 | + expect( |
| 39 | + await renderToString( |
| 40 | + createApp({ |
| 41 | + components: { |
| 42 | + one: { |
| 43 | + template: `<div><slot/></div>` |
| 44 | + } |
| 45 | + }, |
| 46 | + template: `<one><template v-if="false"/></one>` |
| 47 | + }) |
| 48 | + ) |
| 49 | + ).toBe(`<div><!--[--><!--]--></div>`) |
| 50 | + }) |
| 51 | + |
| 52 | + test('multiple elements', async () => { |
| 53 | + expect( |
| 54 | + await renderToString( |
| 55 | + createApp({ |
| 56 | + components, |
| 57 | + template: `<one><div>one</div><div>two</div></one>` |
| 58 | + }) |
| 59 | + ) |
| 60 | + ).toBe(`<div><!--[--><div>one</div><div>two</div><!--]--></div>`) |
| 61 | + }) |
| 62 | + |
| 63 | + test('fragment slot (template v-if)', async () => { |
| 64 | + expect( |
| 65 | + await renderToString( |
| 66 | + createApp({ |
| 67 | + components, |
| 68 | + template: `<one><template v-if="true">hello</template></one>` |
| 69 | + }) |
| 70 | + ) |
| 71 | + ).toBe(`<div><!--[--><!--[-->hello<!--]--><!--]--></div>`) |
| 72 | + }) |
| 73 | + |
| 74 | + test('fragment slot (template v-if + multiple elements)', async () => { |
| 75 | + expect( |
| 76 | + await renderToString( |
| 77 | + createApp({ |
| 78 | + components, |
| 79 | + template: `<one><template v-if="true"><div>one</div><div>two</div></template></one>` |
| 80 | + }) |
| 81 | + ) |
| 82 | + ).toBe( |
| 83 | + `<div><!--[--><!--[--><div>one</div><div>two</div><!--]--><!--]--></div>` |
| 84 | + ) |
| 85 | + }) |
| 86 | +}) |
0 commit comments