ssrPortal.spec.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { createApp, h, Portal } from 'vue'
  2. import { renderToString, SSRContext } from '../src/renderToString'
  3. import { ssrRenderPortal } from '../src/helpers/ssrRenderPortal'
  4. describe('ssrRenderPortal', () => {
  5. test('portal rendering (compiled)', async () => {
  6. const ctx = {
  7. portals: {}
  8. } as SSRContext
  9. await renderToString(
  10. createApp({
  11. data() {
  12. return { msg: 'hello' }
  13. },
  14. ssrRender(_ctx, _push, _parent) {
  15. ssrRenderPortal(
  16. _push => {
  17. _push(`<div>content</div>`)
  18. },
  19. '#target',
  20. _parent
  21. )
  22. }
  23. }),
  24. ctx
  25. )
  26. expect(ctx.portals!['#target']).toBe(`<div>content</div>`)
  27. })
  28. test('portal rendering (vnode)', async () => {
  29. const ctx: SSRContext = {}
  30. await renderToString(
  31. h(
  32. Portal,
  33. {
  34. target: `#target`
  35. },
  36. h('span', 'hello')
  37. ),
  38. ctx
  39. )
  40. expect(ctx.portals!['#target']).toBe('<span>hello</span>')
  41. })
  42. })