component.spec.ts 879 B

12345678910111213141516171819202122232425262728293031
  1. import { ref, watchEffect } from '@vue/runtime-dom'
  2. import { renderEffect, setText, template } from '../src'
  3. import { makeRender } from './_utils'
  4. import type { VaporComponentInstance } from '../src/component'
  5. const define = makeRender()
  6. // TODO port tests from rendererComponent.spec.ts
  7. describe('component', () => {
  8. test('unmountComponent', async () => {
  9. const { host, app, instance } = define(() => {
  10. const count = ref(0)
  11. const t0 = template('<div></div>')
  12. const n0 = t0()
  13. watchEffect(() => {
  14. setText(n0, count.value)
  15. })
  16. renderEffect(() => {})
  17. return n0
  18. }).render()
  19. const i = instance as VaporComponentInstance
  20. expect(i.scope.effects.length).toBe(2)
  21. expect(host.innerHTML).toBe('<div>0</div>')
  22. app.unmount()
  23. expect(host.innerHTML).toBe('')
  24. expect(i.scope.effects.length).toBe(0)
  25. })
  26. })