fix(portal): portal should always remove its children when unmounted

This commit is contained in:
Evan You
2020-03-25 17:27:55 -04:00
parent cb31eb4d0a
commit 16cd8eee78
5 changed files with 48 additions and 3 deletions

View File

@@ -76,4 +76,21 @@ describe('renderer: portal', () => {
expect(serializeInner(target)).toMatchSnapshot()
})
test('should remove children when unmounted', () => {
const target = nodeOps.createElement('div')
const root = nodeOps.createElement('div')
const Comp = defineComponent(() => () => [
h(Portal, { target }, h('div', 'teleported')),
h('div', 'root')
])
render(h(Comp), root)
expect(serializeInner(target)).toMatchInlineSnapshot(
`"<div>teleported</div>"`
)
render(null, root)
expect(serializeInner(target)).toBe('')
})
})

View File

@@ -1,5 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`renderer: portal should remove children when unmounted 1`] = `"<div>teleported</div>"`;
exports[`renderer: portal should update children 1`] = `"<div>teleported</div>"`;
exports[`renderer: portal should update children 2`] = `""`;