Skip to content

Commit 4b60443

Browse files
test: react-plot on server side (#458)
1 parent 49ea616 commit 4b60443

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"@types/d3-shape": "^3.1.0",
6969
"@types/point-in-polygon": "^1.1.1",
7070
"@types/react": "^17.0.45",
71+
"@types/react-dom": "^18.0.10",
7172
"@zakodium/eslint-config": "^6.0.0",
7273
"eslint": "^8.29.0",
7374
"isotopic-distribution": "^1.4.15",

tests/serverside.test.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { test, expect } from '@playwright/experimental-ct-react';
2+
import { ServerSide } from './utils';
3+
4+
test('should render a plot in server-side mode', async ({ mount }) => {
5+
const plot = await mount(<ServerSide />);
6+
const html = await plot.innerHTML();
7+
expect(html).toContain('svg');
8+
});

tests/utils.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ReactNode, useState } from 'react';
2+
import { renderToStaticMarkup } from 'react-dom/server';
23

34
import { Annotations, Plot, ScatterSeries } from '../src';
45
import { Arrow } from '../src/components/Annotations/Arrow';
@@ -13,7 +14,10 @@ interface ChildrenProps {
1314
export function DefaultPlotTest({ children }: ChildrenProps) {
1415
return <Plot {...DEFAULT_PLOT_CONFIG}>{children}</Plot>;
1516
}
16-
17+
export function ServerSide() {
18+
const html = renderToStaticMarkup(<InfraredPlotTest />);
19+
return <div dangerouslySetInnerHTML={{ __html: html }} />;
20+
}
1721
export function InfraredPlotTest({ children }: ChildrenProps) {
1822
return (
1923
<DefaultPlotTest>

0 commit comments

Comments
 (0)