component.spec.ts 675 B

123456789101112131415161718192021222324252627282930
  1. import {
  2. children,
  3. ref,
  4. setText,
  5. template,
  6. unmountComponent,
  7. watchEffect,
  8. } from '../src'
  9. import { describe, expect } from 'vitest'
  10. import { makeRender } from './_utils'
  11. const define = makeRender()
  12. describe('component', () => {
  13. test('unmountComponent', async () => {
  14. const { host, instance } = define(() => {
  15. const count = ref(0)
  16. const t0 = template('<div></div>')
  17. const n0 = t0()
  18. const n1 = children(n0, 0)
  19. watchEffect(() => {
  20. setText(n1, count.value)
  21. })
  22. return n0
  23. }).render()
  24. expect(host.innerHTML).toBe('<div>0</div>')
  25. unmountComponent(instance)
  26. expect(host.innerHTML).toBe('')
  27. })
  28. })