// array
expect(h('div', ['foo'])).toMatchObject(createVNode('div', null, ['foo']))
// default slot
+ const Component = { template: '<br />' }
const slot = () => {}
- expect(h('div', slot)).toMatchObject(createVNode('div', null, slot))
+ expect(h(Component, slot)).toMatchObject(createVNode(Component, null, slot))
+ // single vnode
+ const vnode = h('div')
+ expect(h('div', vnode)).toMatchObject(createVNode('div', null, [vnode]))
// text
expect(h('div', 'foo')).toMatchObject(createVNode('div', null, 'foo'))
})
// array
expect(h('div', {}, ['foo'])).toMatchObject(createVNode('div', {}, ['foo']))
// default slot
+ const Component = { template: '<br />' }
const slot = () => {}
- expect(h('div', {}, slot)).toMatchObject(createVNode('div', {}, slot))
+ expect(h(Component, {}, slot)).toMatchObject(
+ createVNode(Component, {}, slot)
+ )
+ // single vnode
+ const vnode = h('div')
+ expect(h('div', {}, vnode)).toMatchObject(createVNode('div', {}, [vnode]))
// text
expect(h('div', {}, 'foo')).toMatchObject(createVNode('div', {}, 'foo'))
})
test('named slots with null props', () => {
+ const Component = { template: '<br />' }
const slot = () => {}
expect(
- h('div', null, {
+ h(Component, null, {
foo: slot
})
).toMatchObject(
- createVNode('div', null, {
+ createVNode(Component, null, {
foo: slot
})
)
createVNode,
VNodeChildren,
Fragment,
- Portal
+ Portal,
+ isVNode
} from './vnode'
import { isObject, isArray } from '@vue/shared'
import { Ref } from '@vue/reactivity'
// type + omit props + children
// Omit props does NOT support named slots
h('div', []) // array
-h('div', () => {}) // default slot
h('div', 'foo') // text
+h('div', h('br')) // vnode
+h(Component, () => {}) // default slot
// type + props + children
h('div', {}, []) // array
-h('div', {}, () => {}) // default slot
-h('div', {}, {}) // named slots
h('div', {}, 'foo') // text
+h('div', {}, h('br')) // vnode
+h(Component, {}, () => {}) // default slot
+h(Component, {}, {}) // named slots
// named slots without props requires explicit `null` to avoid ambiguity
-h('div', null, {})
+h(Component, null, {})
**/
export interface RawProps {
| string
| number
| boolean
+ | VNode
| VNodeChildren
| (() => any)
): VNode {
if (arguments.length === 2) {
if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
+ // single vnode without props
+ if (isVNode(propsOrChildren)) {
+ return createVNode(type, null, [propsOrChildren])
+ }
// props without children
return createVNode(type, propsOrChildren)
} else {
return createVNode(type, null, propsOrChildren)
}
} else {
+ if (isVNode(children)) {
+ children = [children]
+ }
return createVNode(type, propsOrChildren, children)
}
}