|
4 | 4 | createComponent as createComp, |
5 | 5 | createComponent, |
6 | 6 | } from '../../src/component' |
| 7 | +import { withVaporCtx } from '../../src' |
7 | 8 | import { |
8 | 9 | type VaporDirective, |
9 | 10 | VaporTeleport, |
@@ -704,7 +705,42 @@ function runSharedTests(deferMode: boolean): void { |
704 | 705 | expect(target.innerHTML).toBe('<div>teleported</div>') |
705 | 706 | }) |
706 | 707 |
|
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 | + }) |
708 | 744 |
|
709 | 745 | test('should update target', async () => { |
710 | 746 | const targetA = document.createElement('div') |
|
0 commit comments