await nextTick()
expect(serializeInner(root)).toBe(`foo`)
})
+
+ test('support null in required + multiple-type declarations', () => {
+ const Comp = {
+ props: {
+ foo: { type: [Function, null], required: true }
+ },
+ render() {}
+ }
+ const root = nodeOps.createElement('div')
+ expect(() => {
+ render(h(Comp, { foo: () => {} }), root)
+ }).not.toThrow()
+
+ expect(() => {
+ render(h(Comp, { foo: null }), root)
+ }).not.toThrow()
+ })
})
// so that it works across vms / iframes.
function getType(ctor: Prop<any>): string {
const match = ctor && ctor.toString().match(/^\s*function (\w+)/)
- return match ? match[1] : ''
+ return match ? match[1] : ctor === null ? 'null' : ''
}
function isSameType(a: Prop<any>, b: Prop<any>): boolean {
valid = isObject(value)
} else if (expectedType === 'Array') {
valid = isArray(value)
+ } else if (expectedType === 'null') {
+ valid = value === null
} else {
valid = value instanceof type
}
): string {
let message =
`Invalid prop: type check failed for prop "${name}".` +
- ` Expected ${expectedTypes.map(capitalize).join(', ')}`
+ ` Expected ${expectedTypes.map(capitalize).join(' | ')}`
const expectedType = expectedTypes[0]
const receivedType = toRawType(value)
const expectedValue = styleValue(value, expectedType)