fix: dynamic component fallback to native element

fix #870
This commit is contained in:
Evan You
2020-03-23 14:47:04 -04:00
parent 1b2149dbb2
commit f529dbde23
7 changed files with 80 additions and 34 deletions

View File

@@ -6,11 +6,14 @@ import {
Component,
Directive,
resolveDynamicComponent,
h
h,
serializeInner
} from '@vue/runtime-test'
import { mockWarn } from '@vue/shared'
describe('resolveAssets', () => {
mockWarn()
test('should work', () => {
const FooBar = () => null
const BarBaz = { mounted: () => null }
@@ -63,8 +66,6 @@ describe('resolveAssets', () => {
})
describe('warning', () => {
mockWarn()
test('used outside render() or setup()', () => {
resolveComponent('foo')
expect(
@@ -128,5 +129,22 @@ describe('resolveAssets', () => {
expect(bar).toBe(dynamicComponents.bar)
expect(baz).toBe(dynamicComponents.baz)
})
test('resolve dynamic component should fallback to plain element without warning', () => {
const Root = {
setup() {
return () => {
return h(resolveDynamicComponent('div') as string, null, {
default: () => 'hello'
})
}
}
}
const app = createApp(Root)
const root = nodeOps.createElement('div')
app.mount(root)
expect(serializeInner(root)).toBe('<div>hello</div>')
})
})
})

View File

@@ -106,7 +106,7 @@ describe('vnode', () => {
const vnode = createVNode('p', null, ['foo'])
expect(vnode.children).toMatchObject(['foo'])
expect(vnode.shapeFlag).toBe(
ShapeFlags.ELEMENT + ShapeFlags.ARRAY_CHILDREN
ShapeFlags.ELEMENT | ShapeFlags.ARRAY_CHILDREN
)
})
@@ -114,7 +114,7 @@ describe('vnode', () => {
const vnode = createVNode('p', null, { foo: 'foo' })
expect(vnode.children).toMatchObject({ foo: 'foo' })
expect(vnode.shapeFlag).toBe(
ShapeFlags.ELEMENT + ShapeFlags.SLOTS_CHILDREN
ShapeFlags.ELEMENT | ShapeFlags.SLOTS_CHILDREN
)
})
@@ -122,7 +122,7 @@ describe('vnode', () => {
const vnode = createVNode('p', null, nop)
expect(vnode.children).toMatchObject({ default: nop })
expect(vnode.shapeFlag).toBe(
ShapeFlags.ELEMENT + ShapeFlags.SLOTS_CHILDREN
ShapeFlags.ELEMENT | ShapeFlags.SLOTS_CHILDREN
)
})
@@ -130,7 +130,19 @@ describe('vnode', () => {
const vnode = createVNode('p', null, 'foo')
expect(vnode.children).toBe('foo')
expect(vnode.shapeFlag).toBe(
ShapeFlags.ELEMENT + ShapeFlags.TEXT_CHILDREN
ShapeFlags.ELEMENT | ShapeFlags.TEXT_CHILDREN
)
})
test('element with slots', () => {
const children = [createVNode('span', null, 'hello')]
const vnode = createVNode('div', null, {
default: () => children
})
expect(vnode.children).toBe(children)
expect(vnode.shapeFlag).toBe(
ShapeFlags.ELEMENT | ShapeFlags.ARRAY_CHILDREN
)
})
})