]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(vapor): componentAttrs
authorEvan You <evan@vuejs.org>
Tue, 10 Dec 2024 11:22:25 +0000 (19:22 +0800)
committerEvan You <evan@vuejs.org>
Tue, 10 Dec 2024 11:22:25 +0000 (19:22 +0800)
packages/runtime-vapor/__tests__/_utils.ts
packages/runtime-vapor/__tests__/component.spec.ts
packages/runtime-vapor/__tests__/componentAttrs.spec.ts

index 626764881dab58b5c736cff61dbf016f15555e7a..6900fa67d0be227709f8aa8f6c9c37e55d53c2af 100644 (file)
@@ -55,7 +55,8 @@ export function makeRender<C = VaporComponent>(
     }
 
     function mount(container: string | ParentNode = host) {
-      instance = app.mount(container) as any as VaporComponentInstance
+      app.mount(container)
+      instance = app._instance as VaporComponentInstance
       return res()
     }
 
index 75d00347167b6b5f25eca9a7d5d5b0f14efd5049..a84125b523206dcc78dc56570a54bd0857115f66 100644 (file)
@@ -1,22 +1,31 @@
 import { ref, watchEffect } from '@vue/runtime-dom'
-import { setText, template } from '../src'
+import { renderEffect, setText, template } from '../src'
 import { makeRender } from './_utils'
+import type { VaporComponentInstance } from '../src/component'
 
 const define = makeRender()
 
+// TODO port tests from rendererComponent.spec.ts
+
 describe('component', () => {
   test('unmountComponent', async () => {
-    const { host, app } = define(() => {
+    const { host, app, instance } = define(() => {
       const count = ref(0)
       const t0 = template('<div></div>')
       const n0 = t0()
       watchEffect(() => {
         setText(n0, count.value)
       })
+      renderEffect(() => {})
       return n0
     }).render()
+
+    const i = instance as VaporComponentInstance
+    expect(i.scope.effects.length).toBe(2)
     expect(host.innerHTML).toBe('<div>0</div>')
+
     app.unmount()
     expect(host.innerHTML).toBe('')
+    expect(i.scope.effects.length).toBe(0)
   })
 })
index 78404b3c61e2cefe591e04d0946466099c6b5d98..fccc2413762035de1e8291b04bf0a8e2c97c1eb4 100644 (file)
@@ -1,27 +1,17 @@
-import {
-  createComponent,
-  getCurrentInstance,
-  nextTick,
-  ref,
-  setInheritAttrs,
-  setText,
-  template,
-  watchEffect,
-} from '../src'
+import { nextTick, ref, watchEffect } from '@vue/runtime-dom'
+import { createComponent, setText, template } from '../src'
 import { makeRender } from './_utils'
 
 const define = makeRender<any>()
 
-describe.todo('attribute fallthrough', () => {
+describe('attribute fallthrough', () => {
   it('should allow attrs to fallthrough', async () => {
     const t0 = template('<div>')
     const { component: Child } = define({
       props: ['foo'],
-      render() {
-        const instance = getCurrentInstance()!
+      setup(props: any) {
         const n0 = t0() as Element
-        setInheritAttrs()
-        watchEffect(() => setText(n0, instance.props.foo))
+        watchEffect(() => setText(n0, props.foo))
         return n0
       },
     })
@@ -30,17 +20,12 @@ describe.todo('attribute fallthrough', () => {
     const id = ref('a')
     const { host } = define({
       setup() {
-        return { foo, id }
-      },
-      render(_ctx: Record<string, any>) {
         return createComponent(
           Child,
-          [
-            {
-              foo: () => _ctx.foo,
-              id: () => _ctx.id,
-            },
-          ],
+          {
+            foo: () => foo.value,
+            id: () => id.value,
+          },
           null,
           true,
         )
@@ -62,11 +47,9 @@ describe.todo('attribute fallthrough', () => {
     const { component: Child } = define({
       props: ['foo'],
       inheritAttrs: false,
-      render() {
-        const instance = getCurrentInstance()!
+      setup(props: any) {
         const n0 = t0() as Element
-        setInheritAttrs()
-        watchEffect(() => setText(n0, instance.props.foo))
+        watchEffect(() => setText(n0, props.foo))
         return n0
       },
     })
@@ -75,17 +58,12 @@ describe.todo('attribute fallthrough', () => {
     const id = ref('a')
     const { host } = define({
       setup() {
-        return { foo, id }
-      },
-      render(_ctx: Record<string, any>) {
         return createComponent(
           Child,
-          [
-            {
-              foo: () => _ctx.foo,
-              id: () => _ctx.id,
-            },
-          ],
+          {
+            foo: () => foo.value,
+            id: () => id.value,
+          },
           null,
           true,
         )
@@ -106,24 +84,20 @@ describe.todo('attribute fallthrough', () => {
     const t0 = template('<div>')
     const { component: Grandson } = define({
       props: ['custom-attr'],
-      render() {
-        const instance = getCurrentInstance()!
+      setup(_: any, { attrs }: any) {
         const n0 = t0() as Element
-        setInheritAttrs()
-        watchEffect(() => setText(n0, instance.attrs.foo))
+        watchEffect(() => setText(n0, attrs.foo))
         return n0
       },
     })
 
     const { component: Child } = define({
-      render() {
+      setup() {
         const n0 = createComponent(
           Grandson,
-          [
-            {
-              'custom-attr': () => 'custom-attr',
-            },
-          ],
+          {
+            'custom-attr': () => 'custom-attr',
+          },
           null,
           true,
         )
@@ -135,17 +109,12 @@ describe.todo('attribute fallthrough', () => {
     const id = ref('a')
     const { host } = define({
       setup() {
-        return { foo, id }
-      },
-      render(_ctx: Record<string, any>) {
         return createComponent(
           Child,
-          [
-            {
-              foo: () => _ctx.foo,
-              id: () => _ctx.id,
-            },
-          ],
+          {
+            foo: () => foo.value,
+            id: () => id.value,
+          },
           null,
           true,
         )