Skip to content

Commit a19d8f7

Browse files
authored
test(runtime-vapor): add test for teleport work with SVG (#14103)
1 parent 888d953 commit a19d8f7

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

packages/runtime-vapor/__tests__/components/Teleport.spec.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
createComponent as createComp,
55
createComponent,
66
} from '../../src/component'
7+
import { withVaporCtx } from '../../src'
78
import {
89
type VaporDirective,
910
VaporTeleport,
@@ -704,7 +705,42 @@ function runSharedTests(deferMode: boolean): void {
704705
expect(target.innerHTML).toBe('<div>teleported</div>')
705706
})
706707

707-
test.todo('should work with SVG', async () => {})
708+
test('should work with SVG', async () => {
709+
const svg = ref()
710+
const circle = ref()
711+
const { host } = define({
712+
setup() {
713+
const _setTemplateRef = createTemplateRefSetter()
714+
const n0 = template('<svg></svg>', false, 1)() as any
715+
const n1 = createIf(
716+
() => svg.value,
717+
() => {
718+
const n4 = createComponent(
719+
VaporTeleport,
720+
{ to: () => svg.value },
721+
{
722+
default: withVaporCtx(() => {
723+
const n3 = template('<circle></circle>', false, 1)() as any
724+
_setTemplateRef(n3, circle, undefined, undefined, 'circle')
725+
return n3
726+
}),
727+
},
728+
)
729+
return n4
730+
},
731+
)
732+
_setTemplateRef(n0, svg, undefined, undefined, 'svg')
733+
return [n0, n1]
734+
},
735+
}).render()
736+
737+
await nextTick()
738+
expect(host.innerHTML).toBe(
739+
'<svg><circle></circle></svg><!--teleport start--><!--teleport end--><!--if-->',
740+
)
741+
expect(svg.value.namespaceURI).toBe('http://www.w3.org/2000/svg')
742+
expect(circle.value.namespaceURI).toBe('http://www.w3.org/2000/svg')
743+
})
708744

709745
test('should update target', async () => {
710746
const targetA = document.createElement('div')

packages/runtime-vapor/src/apiTemplateRef.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export type setRefFn = (
3535
ref: NodeRef,
3636
oldRef?: NodeRef,
3737
refFor?: boolean,
38+
refKey?: string,
3839
) => NodeRef | undefined
3940

4041
export function createTemplateRefSetter(): setRefFn {

0 commit comments

Comments
 (0)