fix(teleport): Teleport into SVG elements (#2648)

fix #2652
This commit is contained in:
Yasser Lahbibi
2020-11-30 23:30:41 +01:00
committed by GitHub
parent 7a1a782642
commit cd92836223
2 changed files with 41 additions and 3 deletions

View File

@@ -7,10 +7,11 @@ import {
Text,
ref,
nextTick,
markRaw
markRaw,
defineComponent
} from '@vue/runtime-test'
import { createVNode, Fragment } from '../../src/vnode'
import { compile } from 'vue'
import { compile, render as domRender } from 'vue'
describe('renderer: teleport', () => {
test('should work', () => {
@@ -33,6 +34,37 @@ describe('renderer: teleport', () => {
)
})
test('should work with SVG', async () => {
const root = document.createElement('div')
const svg = ref()
const circle = ref()
const Comp = defineComponent({
setup() {
return {
svg,
circle
}
},
template: `
<svg ref="svg"></svg>
<teleport :to="svg" v-if="svg">
<circle ref="circle"></circle>
</teleport>`
})
domRender(h(Comp), root)
await nextTick()
expect(root.innerHTML).toMatchInlineSnapshot(
`"<svg><circle></circle></svg><!--teleport start--><!--teleport end-->"`
)
expect(svg.value.namespaceURI).toBe('http://www.w3.org/2000/svg')
expect(circle.value.namespaceURI).toBe('http://www.w3.org/2000/svg')
})
test('should update target', async () => {
const targetA = nodeOps.createElement('div')
const targetB = nodeOps.createElement('div')