ssrWatch.spec.ts 742 B

123456789101112131415161718192021222324252627282930
  1. import { createSSRApp, defineComponent, h, ref, watch } from 'vue'
  2. import { type SSRContext, renderToString } from '../src'
  3. describe('ssr: watch', () => {
  4. // #6013
  5. test('should work w/ flush:sync', async () => {
  6. const App = defineComponent(() => {
  7. const count = ref(0)
  8. let msg = ''
  9. watch(
  10. count,
  11. () => {
  12. msg = 'hello world'
  13. },
  14. { flush: 'sync' },
  15. )
  16. count.value = 1
  17. expect(msg).toBe('hello world')
  18. return () => h('div', null, msg)
  19. })
  20. const app = createSSRApp(App)
  21. const ctx: SSRContext = {}
  22. const html = await renderToString(app, ctx)
  23. expect(ctx.__watcherHandles!.length).toBe(1)
  24. expect(html).toMatch('hello world')
  25. })
  26. })