Skip to content

Commit e3ec27d

Browse files
committed
add react test cases
1 parent cdfa799 commit e3ec27d

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

packages/react/test/index.test.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
44
import { signal, useComputed } from "@preact/signals-react";
55
import { createElement, useMemo, memo, StrictMode } from "react";
66
import { createRoot, Root } from "react-dom/client";
7+
import { renderToStaticMarkup } from "react-dom/server";
78
import { act } from "react-dom/test-utils";
89

910
describe("@preact/signals-react", () => {
@@ -162,6 +163,26 @@ describe("@preact/signals-react", () => {
162163
it("should consistently rerender in strict mode", async () => {
163164
const sig = signal<string>(null!);
164165

166+
const Test = () => <p>{sig.value}</p>;
167+
const App = () => (
168+
<StrictMode>
169+
<Test />
170+
</StrictMode>
171+
);
172+
173+
for (let i = 0; i < 3; i++) {
174+
const value = `${i}`;
175+
176+
act(() => {
177+
sig.value = value;
178+
render(<App />);
179+
});
180+
expect(scratch.textContent).to.equal(value);
181+
}
182+
});
183+
it("should consistently rerender in strict mode (with memo)", async () => {
184+
const sig = signal<string>(null!);
185+
165186
const Test = memo(() => <p>{sig.value}</p>);
166187
const App = () => (
167188
<StrictMode>
@@ -179,5 +200,26 @@ describe("@preact/signals-react", () => {
179200
expect(scratch.textContent).to.equal(value);
180201
}
181202
});
203+
it("should render static markup of a component", async () => {
204+
const count = signal(0);
205+
206+
const Test = () => {
207+
return (
208+
<pre>
209+
{renderToStaticMarkup(<code>{count}</code>)}
210+
{renderToStaticMarkup(<code>{count.value}</code>)}
211+
</pre>
212+
);
213+
};
214+
for (let i = 0; i < 3; i++) {
215+
act(() => {
216+
count.value += 1;
217+
render(<Test />);
218+
});
219+
expect(scratch.textContent).to.equal(
220+
`<code>${count.value}</code><code>${count.value}</code>`
221+
);
222+
}
223+
});
182224
});
183225
});

0 commit comments

Comments
 (0)