]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
test(vapor): apiSetupContext
authorEvan You <evan@vuejs.org>
Tue, 10 Dec 2024 07:50:57 +0000 (15:50 +0800)
committerEvan You <evan@vuejs.org>
Tue, 10 Dec 2024 07:50:57 +0000 (15:50 +0800)
packages/runtime-vapor/__tests__/apiSetupContext.spec.ts
packages/runtime-vapor/__tests__/componentProps.spec.ts

index 4ffcf35cf8c12873f2ac6d6772d6780edc9f1fc2..7eb8a0cf0ea25c7c3b447c98e3f0236dd102ee3e 100644 (file)
@@ -2,24 +2,20 @@ import {
   createComponent,
   createSlot,
   createTextNode,
-  defineComponent,
+  defineVaporComponent,
   delegate,
   delegateEvents,
   insert,
-  nextTick,
-  reactive,
-  ref,
   renderEffect,
   setDynamicProps,
-  setInheritAttrs,
   template,
-  watchEffect,
 } from '../src'
+import { nextTick, reactive, ref, watchEffect } from '@vue/runtime-dom'
 import { makeRender } from './_utils'
 
 const define = makeRender()
 
-describe.todo('api: setup context', () => {
+describe('api: setup context', () => {
   it('should expose return values to template render context', () => {
     const { html } = define({
       setup() {
@@ -49,7 +45,7 @@ describe.todo('api: setup context', () => {
     const count = ref(0)
     let dummy
 
-    const Child = defineComponent({
+    const Child = defineVaporComponent({
       props: { count: Number },
       setup(props) {
         watchEffect(() => {
@@ -74,7 +70,7 @@ describe.todo('api: setup context', () => {
   it('context.attrs', async () => {
     const toggle = ref(true)
 
-    const Child = defineComponent({
+    const Child = defineVaporComponent({
       inheritAttrs: false,
       setup(props, { attrs }) {
         const el = document.createElement('div')
@@ -85,9 +81,9 @@ describe.todo('api: setup context', () => {
 
     const { html } = define({
       render: () =>
-        createComponent(Child, () =>
-          toggle.value ? { id: 'foo' } : { class: 'baz' },
-        ),
+        createComponent(Child, {
+          $: [() => (toggle.value ? { id: 'foo' } : { class: 'baz' })],
+        }),
     }).render()
 
     expect(html()).toMatch(`<div id="foo"></div>`)
@@ -101,15 +97,14 @@ describe.todo('api: setup context', () => {
   it('context.attrs in child component slots', async () => {
     const toggle = ref(true)
 
-    const Wrapper = defineComponent({
+    const Wrapper = defineVaporComponent({
       setup(_) {
         const n0 = createSlot('default')
-        setInheritAttrs(true)
         return n0
       },
     })
 
-    const Child = defineComponent({
+    const Child = defineVaporComponent({
       inheritAttrs: false,
       setup(_: any, { attrs }: any) {
         const n0 = createComponent(Wrapper, null, {
@@ -125,9 +120,9 @@ describe.todo('api: setup context', () => {
 
     const { html } = define({
       render: () =>
-        createComponent(Child, () =>
-          toggle.value ? { id: 'foo' } : { class: 'baz' },
-        ),
+        createComponent(Child, {
+          $: [() => (toggle.value ? { id: 'foo' } : { class: 'baz' })],
+        }),
     }).render()
 
     expect(html()).toMatch(`<div id="foo"></div>`)
@@ -141,7 +136,7 @@ describe.todo('api: setup context', () => {
   it('context.slots', async () => {
     const id = ref('foo')
 
-    const Child = defineComponent({
+    const Child = defineVaporComponent({
       render() {
         return [createSlot('foo'), createSlot('bar')]
       },
@@ -149,16 +144,18 @@ describe.todo('api: setup context', () => {
 
     const { html } = define({
       render() {
-        return createComponent(Child, null, [
-          () => ({
-            name: 'foo',
-            fn: () => createTextNode(() => [id.value]),
-          }),
-          () => ({
-            name: 'bar',
-            fn: () => createTextNode(['bar']),
-          }),
-        ])
+        return createComponent(Child, null, {
+          $: [
+            () => ({
+              name: 'foo',
+              fn: () => createTextNode(() => [id.value]),
+            }),
+            () => ({
+              name: 'bar',
+              fn: () => createTextNode(['bar']),
+            }),
+          ],
+        })
       },
     }).render()
 
@@ -175,7 +172,7 @@ describe.todo('api: setup context', () => {
 
     delegateEvents('click')
 
-    const Child = defineComponent({
+    const Child = defineVaporComponent({
       props: {
         count: { type: Number, default: 1 },
       },
index 875d43d6fd17073483c46157e55e70fb2064dfd8..6d87041f90c04cf18ab54577323fa06fdf930b92 100644 (file)
@@ -17,7 +17,6 @@ import {
   template,
 } from '../src'
 import { makeRender } from './_utils'
-import type { RawProps } from '../src/componentProps'
 
 const define = makeRender<any>()
 
@@ -468,7 +467,7 @@ describe('component: props', () => {
     define(() =>
       createComponent(Comp, {
         $: [() => (passFoo.value ? { foo: 'ok' } : {})],
-      } as RawProps),
+      }),
     ).render()
 
     expect(initialKeys).toMatchObject(['foo'])