parent
							
								
									cbeb9f2d78
								
							
						
					
					
						commit
						70c2d5bbc0
					
				
							
								
								
									
										86
									
								
								packages/server-renderer/__tests__/ssrSlot.spec.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										86
									
								
								packages/server-renderer/__tests__/ssrSlot.spec.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,86 @@
 | 
				
			|||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * @jest-environment node
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { createApp } from 'vue'
 | 
				
			||||||
 | 
					import { renderToString } from '../src/renderToString'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const components = {
 | 
				
			||||||
 | 
					  one: {
 | 
				
			||||||
 | 
					    template: `<div><slot/></div>`
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					describe('ssr: slot', () => {
 | 
				
			||||||
 | 
					  test('text slot', async () => {
 | 
				
			||||||
 | 
					    expect(
 | 
				
			||||||
 | 
					      await renderToString(
 | 
				
			||||||
 | 
					        createApp({
 | 
				
			||||||
 | 
					          components,
 | 
				
			||||||
 | 
					          template: `<one>hello</one>`
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    ).toBe(`<div><!--[-->hello<!--]--></div>`)
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  test('element slot', async () => {
 | 
				
			||||||
 | 
					    expect(
 | 
				
			||||||
 | 
					      await renderToString(
 | 
				
			||||||
 | 
					        createApp({
 | 
				
			||||||
 | 
					          components,
 | 
				
			||||||
 | 
					          template: `<one><div>hi</div></one>`
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    ).toBe(`<div><!--[--><div>hi</div><!--]--></div>`)
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  test('empty slot', async () => {
 | 
				
			||||||
 | 
					    expect(
 | 
				
			||||||
 | 
					      await renderToString(
 | 
				
			||||||
 | 
					        createApp({
 | 
				
			||||||
 | 
					          components: {
 | 
				
			||||||
 | 
					            one: {
 | 
				
			||||||
 | 
					              template: `<div><slot/></div>`
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          template: `<one><template v-if="false"/></one>`
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    ).toBe(`<div><!--[--><!--]--></div>`)
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  test('multiple elements', async () => {
 | 
				
			||||||
 | 
					    expect(
 | 
				
			||||||
 | 
					      await renderToString(
 | 
				
			||||||
 | 
					        createApp({
 | 
				
			||||||
 | 
					          components,
 | 
				
			||||||
 | 
					          template: `<one><div>one</div><div>two</div></one>`
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    ).toBe(`<div><!--[--><div>one</div><div>two</div><!--]--></div>`)
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  test('fragment slot (template v-if)', async () => {
 | 
				
			||||||
 | 
					    expect(
 | 
				
			||||||
 | 
					      await renderToString(
 | 
				
			||||||
 | 
					        createApp({
 | 
				
			||||||
 | 
					          components,
 | 
				
			||||||
 | 
					          template: `<one><template v-if="true">hello</template></one>`
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    ).toBe(`<div><!--[--><!--[-->hello<!--]--><!--]--></div>`)
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  test('fragment slot (template v-if + multiple elements)', async () => {
 | 
				
			||||||
 | 
					    expect(
 | 
				
			||||||
 | 
					      await renderToString(
 | 
				
			||||||
 | 
					        createApp({
 | 
				
			||||||
 | 
					          components,
 | 
				
			||||||
 | 
					          template: `<one><template v-if="true"><div>one</div><div>two</div></template></one>`
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					      )
 | 
				
			||||||
 | 
					    ).toBe(
 | 
				
			||||||
 | 
					      `<div><!--[--><!--[--><div>one</div><div>two</div><!--]--><!--]--></div>`
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					  })
 | 
				
			||||||
 | 
					})
 | 
				
			||||||
@ -82,7 +82,7 @@ export function ssrRenderSlotInner(
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const commentRE = /^<!--.*-->$/
 | 
					const commentRE = /<!--.*?-->/g
 | 
				
			||||||
function isComment(item: SSRBufferItem) {
 | 
					function isComment(item: SSRBufferItem) {
 | 
				
			||||||
  return typeof item === 'string' && commentRE.test(item)
 | 
					  return typeof item === 'string' && !item.replace(commentRE, '').trim()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user