Skip to content

Commit 7751465

Browse files
committed
test(runtime-vapor): component props (optimized props updates)
1 parent ab94425 commit 7751465

File tree

1 file changed

+65
-9
lines changed

1 file changed

+65
-9
lines changed

packages/runtime-vapor/__tests__/componentProps.spec.ts

+65-9
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
// mixins
55
// caching
66

7-
import { defineComponent } from '../src/apiDefineComponent'
8-
97
import type { FunctionalComponent } from '../src/component'
10-
import { getCurrentInstance } from '../src/component'
11-
import { render } from '../src/render'
12-
import { template } from '../src/template'
13-
import { children, setText } from '../src/dom'
14-
import { watchEffect } from '../src/apiWatch'
8+
import {
9+
children,
10+
defineComponent,
11+
getCurrentInstance,
12+
nextTick,
13+
ref,
14+
render,
15+
setText,
16+
template,
17+
watchEffect,
18+
} from '../src'
1519

1620
let host: HTMLElement
1721
const initHost = () => {
@@ -297,10 +301,62 @@ describe('component props (vapor)', () => {
297301
// NOTE: maybe it's unnecessary
298302
// https://github.com/vuejs/core-vapor/pull/99#discussion_r1472647377
299303
test('optimized props updates', async () => {
300-
// TODO:
304+
const Child = defineComponent({
305+
props: ['foo'],
306+
render() {
307+
const instance = getCurrentInstance()!
308+
const t0 = template('<div><!></div>')
309+
const n0 = t0()
310+
const {
311+
0: [n1],
312+
} = children(n0)
313+
watchEffect(() => {
314+
setText(n1, instance.props.foo)
315+
})
316+
return n0
317+
},
318+
})
319+
320+
const foo = ref(1)
321+
const id = ref('a')
322+
const Comp = defineComponent({
323+
setup() {
324+
return { foo, id }
325+
},
326+
render(_ctx: Record<string, any>) {
327+
const t0 = template('')
328+
const n0 = t0()
329+
render(
330+
Child,
331+
{
332+
get foo() {
333+
return _ctx.foo
334+
},
335+
get id() {
336+
return _ctx.id
337+
},
338+
},
339+
n0 as any, // TODO: type
340+
)
341+
return n0
342+
},
343+
})
344+
345+
render(Comp, {}, host)
346+
// expect(host.innerHTML).toBe('<div id="a">1</div>') // TODO: Fallthrough Attributes
347+
expect(host.innerHTML).toBe('<div>1</div>')
348+
349+
foo.value++
350+
await nextTick()
351+
// expect(host.innerHTML).toBe('<div id="a">2</div>') // TODO: Fallthrough Attributes
352+
expect(host.innerHTML).toBe('<div>2</div>')
353+
354+
// id.value = 'b'
355+
// await nextTick()
356+
// expect(host.innerHTML).toBe('<div id="b">2</div>') // TODO: Fallthrough Attributes
301357
})
302358

303-
describe('validator', () => {
359+
test('validator', () => {
304360
// TODO: impl validator
305361
})
306362

0 commit comments

Comments
 (0)