test('default value', () => {
let proxy: any
const defaultFn = jest.fn(() => ({ a: 1 }))
+ const defaultBaz = jest.fn(() => ({ b: 1 }))
const Comp = {
props: {
},
bar: {
default: defaultFn
+ },
+ baz: {
+ type: Function,
+ default: defaultBaz
}
},
render() {
expect(proxy.foo).toBe(2)
const prevBar = proxy.bar
expect(proxy.bar).toEqual({ a: 1 })
+ expect(proxy.baz).toEqual(defaultBaz)
expect(defaultFn).toHaveBeenCalledTimes(1)
+ expect(defaultBaz).toHaveBeenCalledTimes(0)
// #999: updates should not cause default factory of unchanged prop to be
// called again
key: string,
value: unknown
) {
- const opt = options[key]
+ const opt = options[key] as any
if (opt != null) {
const hasDefault = hasOwn(opt, 'default')
// default values
if (hasDefault && value === undefined) {
const defaultValue = opt.default
- value = isFunction(defaultValue) ? defaultValue() : defaultValue
+ value =
+ opt.type !== Function && isFunction(defaultValue)
+ ? defaultValue()
+ : defaultValue
}
// boolean casting
if (opt[BooleanFlags.shouldCast]) {