fix(runtime-core): support attr merging on child with root level comments

fix #904
This commit is contained in:
Evan You
2020-04-03 21:37:58 -04:00
parent 5bf72517ce
commit e42cb54394
2 changed files with 81 additions and 13 deletions

View File

@@ -9,7 +9,8 @@ import {
defineComponent,
openBlock,
createBlock,
FunctionalComponent
FunctionalComponent,
createCommentVNode
} from '@vue/runtime-dom'
import { mockWarn } from '@vue/shared'
@@ -495,4 +496,35 @@ describe('attribute fallthrough', () => {
expect(onClick).toHaveBeenCalledTimes(1)
expect(onClick).toHaveBeenCalledWith('custom')
})
it('should support fallthrough for fragments with single element + comments', () => {
const click = jest.fn()
const Hello = {
setup() {
return () => h(Child, { class: 'foo', onClick: click })
}
}
const Child = {
setup(props: any) {
return () => [
createCommentVNode('hello'),
h('button'),
createCommentVNode('world')
]
}
}
const root = document.createElement('div')
document.body.appendChild(root)
render(h(Hello), root)
expect(root.innerHTML).toBe(
`<!--hello--><button class="foo"></button><!--world-->`
)
const button = root.children[0] as HTMLElement
button.dispatchEvent(new CustomEvent('click'))
expect(click).toHaveBeenCalled()
})
})