Skip to content

Commit

Permalink
test(dom-to-react): add LaTeX snapshot test
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Dec 16, 2024
1 parent b79ac70 commit 038bd12
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
12 changes: 12 additions & 0 deletions __tests__/__snapshots__/dom-to-react.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ exports[`domToReact converts <textarea> correctly 1`] = `
/>
`;
exports[`domToReact converts LaTeX 1`] = `
[
<span
className="math"
>
\\left(\\right)\\rD\\rightarrow\\reals\\ni
</span>,
"
",
]
`;
exports[`domToReact converts SVG element with viewBox attribute 1`] = `
<svg
id="foo"
Expand Down
2 changes: 2 additions & 0 deletions __tests__/data/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ export const html = {
form: '<input type="text" value="foo" checked="checked">',
list: '<ol><li>One</li><li value="2">Two</li></ol>',
template: '<template><article><p>Test</p></article></template>',
latex:
'<span class="math">\\left(\\right)\\rD\\rightarrow\\reals\\ni</span>\r\n',
} as const;
12 changes: 7 additions & 5 deletions __tests__/dom-to-react.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,8 @@ describe('domToReact', () => {
});

it('does not throw an error for void elements', () => {
const reactElements = domToReact(htmlToDOM(html.void));
expect(() => {
render(<div>{reactElements}</div>);
render(<div>{domToReact(htmlToDOM(html.void))}</div>);
}).not.toThrow();
});

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

it('converts custom element with attributes', () => {
const reactElement = domToReact(htmlToDOM(html.customElement));
expect(reactElement).toMatchSnapshot();
expect(domToReact(htmlToDOM(html.customElement))).toMatchSnapshot();
});

it('converts LaTeX', () => {
expect(domToReact(htmlToDOM(html.latex))).toMatchSnapshot();
});
});

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

0 comments on commit 038bd12

Please sign in to comment.