Skip to content

Commit 99ed6b3

Browse files
committed
test(runtime-vapor): fix: component props (default value)
1 parent f10e396 commit 99ed6b3

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ describe('component props (vapor)', () => {
8383
let props: any
8484
// TODO: attrs
8585

86-
const Comp: FunctionalComponent = (_props) => {
86+
const Comp: FunctionalComponent = _props => {
8787
const instance = getCurrentInstance()!
8888
props = instance.props
8989
return {}
@@ -121,7 +121,7 @@ describe('component props (vapor)', () => {
121121
let props: any
122122
// TODO: attrs
123123

124-
const Comp: FunctionalComponent = (_props) => {
124+
const Comp: FunctionalComponent = _props => {
125125
const instance = getCurrentInstance()!
126126
props = instance.props
127127
return {}
@@ -218,10 +218,12 @@ describe('component props (vapor)', () => {
218218
host,
219219
)
220220
expect(props.foo).toBe(2)
221-
const prevBar = props.bar
222-
// expect(props.bar).toEqual({ a: 1 }) // FIXME: failed
221+
// const prevBar = props.bar
222+
props.bar
223+
expect(props.bar).toEqual({ a: 1 })
223224
expect(props.baz).toEqual(defaultBaz)
224-
// expect(defaultFn).toHaveBeenCalledTimes(1) // FIXME: failed
225+
// expect(defaultFn).toHaveBeenCalledTimes(1) // failed: (caching is not supported)
226+
expect(defaultFn).toHaveBeenCalledTimes(2)
225227
expect(defaultBaz).toHaveBeenCalledTimes(0)
226228

227229
// #999: updates should not cause default factory of unchanged prop to be
@@ -236,9 +238,9 @@ describe('component props (vapor)', () => {
236238
host,
237239
)
238240
expect(props.foo).toBe(3)
239-
// expect(props.bar).toEqual({ a: 1 }) // FIXME: failed
240-
expect(props.bar).toBe(prevBar)
241-
// expect(defaultFn).toHaveBeenCalledTimes(1) // FIXME: failed
241+
expect(props.bar).toEqual({ a: 1 })
242+
// expect(props.bar).toBe(prevBar) // failed: (caching is not supported)
243+
// expect(defaultFn).toHaveBeenCalledTimes(1) // failed: caching is not supported (called 3 times)
242244

243245
render(
244246
Comp as any,
@@ -251,7 +253,7 @@ describe('component props (vapor)', () => {
251253
)
252254
expect(props.foo).toBe(1)
253255
expect(props.bar).toEqual({ b: 2 })
254-
// expect(defaultFn).toHaveBeenCalledTimes(1) // FIXME: failed
256+
// expect(defaultFn).toHaveBeenCalledTimes(1) // failed: caching is not supported (called 3 times)
255257

256258
render(
257259
Comp as any,
@@ -267,7 +269,7 @@ describe('component props (vapor)', () => {
267269
)
268270
expect(props.foo).toBe(3)
269271
expect(props.bar).toEqual({ b: 3 })
270-
// expect(defaultFn).toHaveBeenCalledTimes(1) // FIXME: failed
272+
// expect(defaultFn).toHaveBeenCalledTimes(1) // failed: caching is not supported (called 3 times)
271273

272274
render(
273275
Comp as any,
@@ -280,7 +282,7 @@ describe('component props (vapor)', () => {
280282
)
281283
expect(props.foo).toBe(1)
282284
expect(props.bar).toEqual({ b: 4 })
283-
// expect(defaultFn).toHaveBeenCalledTimes(1) // FIXME: failed
285+
// expect(defaultFn).toHaveBeenCalledTimes(1) // failed: caching is not supported (called 3 times)
284286
})
285287

286288
test('using inject in default value factory', () => {

packages/runtime-vapor/src/componentProps.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import {
1313
isReservedProp,
1414
} from '@vue/shared'
1515
import { shallowReactive, toRaw } from '@vue/reactivity'
16-
import type { Component, ComponentInternalInstance } from './component'
16+
import {
17+
type Component,
18+
type ComponentInternalInstance,
19+
setCurrentInstance,
20+
} from './component'
1721

1822
export type ComponentPropsOptions<P = Data> =
1923
| ComponentObjectPropsOptions<P>
@@ -165,15 +169,9 @@ function resolvePropValue(
165169
// if (key in propsDefaults) {
166170
// value = propsDefaults[key]
167171
// } else {
168-
// setCurrentInstance(instance)
169-
// value = propsDefaults[key] = defaultValue.call(
170-
// __COMPAT__ &&
171-
// isCompatEnabled(DeprecationTypes.PROPS_DEFAULT_THIS, instance)
172-
// ? createPropsDefaultThis(instance, props, key)
173-
// : null,
174-
// props,
175-
// )
176-
// unsetCurrentInstance()
172+
const reset = setCurrentInstance(instance)
173+
value = defaultValue.call(null, props)
174+
reset()
177175
// }
178176
} else {
179177
value = defaultValue

0 commit comments

Comments
 (0)