File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -158,6 +158,7 @@ describe('component props', () => {
158
158
test ( 'default value' , ( ) => {
159
159
let proxy : any
160
160
const defaultFn = jest . fn ( ( ) => ( { a : 1 } ) )
161
+ const defaultBaz = jest . fn ( ( ) => ( { b : 1 } ) )
161
162
162
163
const Comp = {
163
164
props : {
@@ -166,6 +167,10 @@ describe('component props', () => {
166
167
} ,
167
168
bar : {
168
169
default : defaultFn
170
+ } ,
171
+ baz : {
172
+ type : Function ,
173
+ default : defaultBaz
169
174
}
170
175
} ,
171
176
render ( ) {
@@ -178,7 +183,9 @@ describe('component props', () => {
178
183
expect ( proxy . foo ) . toBe ( 2 )
179
184
const prevBar = proxy . bar
180
185
expect ( proxy . bar ) . toEqual ( { a : 1 } )
186
+ expect ( proxy . baz ) . toEqual ( defaultBaz )
181
187
expect ( defaultFn ) . toHaveBeenCalledTimes ( 1 )
188
+ expect ( defaultBaz ) . toHaveBeenCalledTimes ( 0 )
182
189
183
190
// #999: updates should not cause default factory of unchanged prop to be
184
191
// called again
Original file line number Diff line number Diff line change @@ -270,13 +270,16 @@ function resolvePropValue(
270
270
key : string ,
271
271
value : unknown
272
272
) {
273
- const opt = options [ key ]
273
+ const opt = options [ key ] as any
274
274
if ( opt != null ) {
275
275
const hasDefault = hasOwn ( opt , 'default' )
276
276
// default values
277
277
if ( hasDefault && value === undefined ) {
278
278
const defaultValue = opt . default
279
- value = isFunction ( defaultValue ) ? defaultValue ( ) : defaultValue
279
+ value =
280
+ opt . type !== Function && isFunction ( defaultValue )
281
+ ? defaultValue ( )
282
+ : defaultValue
280
283
}
281
284
// boolean casting
282
285
if ( opt [ BooleanFlags . shouldCast ] ) {
You can’t perform that action at this time.
0 commit comments