|
4 | 4 | // mixins
|
5 | 5 | // caching
|
6 | 6 |
|
7 |
| -import { defineComponent } from '../src/apiDefineComponent' |
8 |
| - |
9 | 7 | 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' |
15 | 19 |
|
16 | 20 | let host: HTMLElement
|
17 | 21 | const initHost = () => {
|
@@ -297,10 +301,62 @@ describe('component props (vapor)', () => {
|
297 | 301 | // NOTE: maybe it's unnecessary
|
298 | 302 | // https://github.com/vuejs/core-vapor/pull/99#discussion_r1472647377
|
299 | 303 | 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 |
301 | 357 | })
|
302 | 358 |
|
303 |
| - describe('validator', () => { |
| 359 | + test('validator', () => { |
304 | 360 | // TODO: impl validator
|
305 | 361 | })
|
306 | 362 |
|
|
0 commit comments