Skip to content

Commit 038bd12

Browse files
test(dom-to-react): add LaTeX snapshot test
1 parent b79ac70 commit 038bd12

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

__tests__/__snapshots__/dom-to-react.test.tsx.snap

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ exports[`domToReact converts <textarea> correctly 1`] = `
66
/>
77
`;
88
9+
exports[`domToReact converts LaTeX 1`] = `
10+
[
11+
<span
12+
className="math"
13+
>
14+
\\left(\\right)\\rD\\rightarrow\\reals\\ni
15+
</span>,
16+
"
17+
",
18+
]
19+
`;
20+
921
exports[`domToReact converts SVG element with viewBox attribute 1`] = `
1022
<svg
1123
id="foo"

__tests__/data/html.ts

+2
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ export const html = {
1919
form: '<input type="text" value="foo" checked="checked">',
2020
list: '<ol><li>One</li><li value="2">Two</li></ol>',
2121
template: '<template><article><p>Test</p></article></template>',
22+
latex:
23+
'<span class="math">\\left(\\right)\\rD\\rightarrow\\reals\\ni</span>\r\n',
2224
} as const;

__tests__/dom-to-react.test.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ describe('domToReact', () => {
5656
});
5757

5858
it('does not throw an error for void elements', () => {
59-
const reactElements = domToReact(htmlToDOM(html.void));
6059
expect(() => {
61-
render(<div>{reactElements}</div>);
60+
render(<div>{domToReact(htmlToDOM(html.void))}</div>);
6261
}).not.toThrow();
6362
});
6463

@@ -80,8 +79,11 @@ describe('domToReact', () => {
8079
});
8180

8281
it('converts custom element with attributes', () => {
83-
const reactElement = domToReact(htmlToDOM(html.customElement));
84-
expect(reactElement).toMatchSnapshot();
82+
expect(domToReact(htmlToDOM(html.customElement))).toMatchSnapshot();
83+
});
84+
85+
it('converts LaTeX', () => {
86+
expect(domToReact(htmlToDOM(html.latex))).toMatchSnapshot();
8587
});
8688
});
8789

@@ -104,7 +106,7 @@ describe('library option', () => {
104106
expect(React.isValidElement(parsedElement)).toBe(false);
105107
expect(Preact.isValidElement(parsedElement)).toBe(true);
106108
// remove `__v` key since it's causing test equality to fail
107-
// @ts-expect-error Property '__v' does not exist on type '...roperty '__v' does not exist on type 'string'.
109+
// @ts-expect-error Property '__v' does not exist on type 'string'.
108110
delete parsedElement.__v;
109111
delete preactElement.__v;
110112
expect(parsedElement).toEqual(preactElement);

0 commit comments

Comments
 (0)