|
1 |
| -describe.todo('MathML support', () => {}) |
| 1 | +import { makeRender } from '../_utils' |
| 2 | +import { template } from '../../src/dom/template' |
| 3 | +import { child } from '../../src/dom/node' |
| 4 | +import { setClass } from '../../src/dom/prop' |
| 5 | +import { renderEffect } from '../../src' |
| 6 | +import { nextTick, ref } from '@vue/runtime-dom' |
| 7 | + |
| 8 | +const define = makeRender() |
| 9 | + |
| 10 | +describe('MathML support', () => { |
| 11 | + afterEach(() => { |
| 12 | + document.body.innerHTML = '' |
| 13 | + }) |
| 14 | + |
| 15 | + test('should mount elements with correct html namespace', () => { |
| 16 | + define({ |
| 17 | + setup() { |
| 18 | + const t0 = template( |
| 19 | + '<math display="block" id="e0"><semantics id="e1"><mrow id="e2"><msup><mi>x</mi><mn>2</mn></msup><mo>+</mo><mi>y</mi></mrow><annotation-xml encoding="text/html" id="e3"><div id="e4"></div><svg id="e5"></svg></annotation-xml></semantics></math>', |
| 20 | + true, |
| 21 | + 2, |
| 22 | + ) |
| 23 | + const n0 = t0() |
| 24 | + return n0 |
| 25 | + }, |
| 26 | + }).render() |
| 27 | + |
| 28 | + const e0 = document.getElementById('e0')! |
| 29 | + expect(e0.namespaceURI).toMatch('Math') |
| 30 | + expect(e0.querySelector('#e1')!.namespaceURI).toMatch('Math') |
| 31 | + expect(e0.querySelector('#e2')!.namespaceURI).toMatch('Math') |
| 32 | + expect(e0.querySelector('#e3')!.namespaceURI).toMatch('Math') |
| 33 | + expect(e0.querySelector('#e4')!.namespaceURI).toMatch('xhtml') |
| 34 | + expect(e0.querySelector('#e5')!.namespaceURI).toMatch('svg') |
| 35 | + }) |
| 36 | + |
| 37 | + test.todo('should patch elements with correct namespaces', async () => { |
| 38 | + const cls = ref('foo') |
| 39 | + define({ |
| 40 | + setup() { |
| 41 | + const t0 = template( |
| 42 | + '<div><math id="f1"><annotation encoding="text/html"><div id="f2"></div></annotation></math></div>', |
| 43 | + true, |
| 44 | + ) |
| 45 | + const n2 = t0() as HTMLElement |
| 46 | + const n1 = child(n2) as HTMLElement |
| 47 | + const p0 = child(n1) as HTMLElement |
| 48 | + const n0 = child(p0) as HTMLElement |
| 49 | + renderEffect(() => { |
| 50 | + const _cls = cls |
| 51 | + setClass(n1, _cls) |
| 52 | + // problem is n0 is undefined here |
| 53 | + setClass(n0, _cls) |
| 54 | + }) |
| 55 | + return n2 |
| 56 | + }, |
| 57 | + }).render() |
| 58 | + |
| 59 | + const f1 = document.querySelector('#f1')! |
| 60 | + const f2 = document.querySelector('#f2')! |
| 61 | + expect(f1.getAttribute('class')).toBe('foo') |
| 62 | + expect(f2.className).toBe('foo') |
| 63 | + |
| 64 | + cls.value = 'bar' |
| 65 | + await nextTick() |
| 66 | + expect(f1.getAttribute('class')).toBe('bar') |
| 67 | + expect(f2.className).toBe('bar') |
| 68 | + }) |
| 69 | +}) |
0 commit comments