返回 slidev
KaTexBlockWrapper.test.ts
根目录 / packages / client / builtin / KaTexBlockWrapper.test.ts
1 import { describe, expect, it } from 'vitest'
2 import { collectKatexEquationLines } from './katex-lines'
3
4 function fakeElement(options: {
5 parent?: Element | null
6 closest?: Element | null
7 children?: Element[]
8 } = {}) {
9 const el = {
10 parentElement: options.parent ?? null,
11 closest: () => options.closest ?? null,
12 querySelectorAll: () => options.children ?? [],
13 }
14 return el as unknown as Element
15 }
16
17 describe('collectKatexEquationLines', () => {
18 it('ignores nested KaTeX tables when mapping equation lines', () => {
19 const rowA1 = fakeElement()
20 const rowA2 = fakeElement()
21 const rowB1 = fakeElement()
22 const rowB2 = fakeElement()
23 const nestedRow = fakeElement()
24
25 const outerLeftParent = fakeElement({
26 children: [rowA1, rowA2],
27 })
28 const outerRightParent = fakeElement({
29 children: [rowB1, rowB2],
30 })
31 const nestedParent = fakeElement({
32 parent: fakeElement({ closest: outerLeftParent }),
33 children: [nestedRow],
34 })
35
36 const root = fakeElement({
37 children: [outerLeftParent, nestedParent, outerRightParent],
38 })
39
40 expect(collectKatexEquationLines(root)).toEqual([
41 [rowA1, rowB1],
42 [rowA2, rowB2],
43 ])
44 })
45 })
46
46 lines TYPESCRIPT