fix(teleport): targetAnchor should also be removed when unmounted (#2870)

* fix(teleport): targetAnchor should also be removed when unmounted

* fix(teleport): targetAnchor should also be removed when unmounted
This commit is contained in:
2021-03-23 17:19:09 +08:00
committed by GitHub
parent 3b3a9a1f52
commit 21d1288133
3 changed files with 34 additions and 29 deletions

View File

@@ -128,19 +128,23 @@ describe('renderer: teleport', () => {
const target = nodeOps.createElement('div')
const root = nodeOps.createElement('div')
render(
h(() => [
h(Teleport, { to: target }, h('div', 'teleported')),
h('div', 'root')
]),
root
)
expect(serializeInner(target)).toMatchInlineSnapshot(
`"<div>teleported</div>"`
)
function testUnmount(props: any) {
render(
h(() => [h(Teleport, props, h('div', 'teleported')), h('div', 'root')]),
root
)
expect(serializeInner(target)).toMatchInlineSnapshot(
props.disabled ? `""` : `"<div>teleported</div>"`
)
render(null, root)
expect(serializeInner(target)).toBe('')
render(null, root)
expect(serializeInner(target)).toBe('')
expect(target.children.length).toBe(0)
}
testUnmount({ to: target, disabled: false })
testUnmount({ to: target, disabled: true })
testUnmount({ to: null, disabled: true })
})
test('multiple teleport with same target', () => {