Skip to content

Commit 4b30468

Browse files
committed
Update StrictMode tests to more closely match the issue repro
1 parent a142a8d commit 4b30468

1 file changed

Lines changed: 26 additions & 19 deletions

File tree

packages/react/test/index.test.tsx

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ describe("@preact/signals-react", () => {
212212
});
213213

214214
it("should consistently rerender in strict mode", async () => {
215-
const sig = signal<string>(null!);
215+
const sig = signal(-1);
216216

217217
const Test = () => <p>{sig.value}</p>;
218218
const App = () => (
@@ -221,18 +221,19 @@ describe("@preact/signals-react", () => {
221221
</StrictMode>
222222
);
223223

224-
for (let i = 0; i < 3; i++) {
225-
const value = `${i}`;
224+
await render(<App />);
225+
expect(scratch.textContent).to.equal("-1");
226226

227+
for (let i = 0; i < 3; i++) {
227228
await act(async () => {
228-
sig.value = value;
229-
await render(<App />);
229+
sig.value = i;
230230
});
231-
expect(scratch.textContent).to.equal(value);
231+
expect(scratch.textContent).to.equal("" + i);
232232
}
233233
});
234+
234235
it("should consistently rerender in strict mode (with memo)", async () => {
235-
const sig = signal<string>(null!);
236+
const sig = signal(-1);
236237

237238
const Test = memo(() => <p>{sig.value}</p>);
238239
const App = () => (
@@ -241,16 +242,17 @@ describe("@preact/signals-react", () => {
241242
</StrictMode>
242243
);
243244

244-
for (let i = 0; i < 3; i++) {
245-
const value = `${i}`;
245+
await render(<App />);
246+
expect(scratch.textContent).to.equal("-1");
246247

248+
for (let i = 0; i < 3; i++) {
247249
await act(async () => {
248-
sig.value = value;
249-
await render(<App />);
250+
sig.value = i;
250251
});
251-
expect(scratch.textContent).to.equal(value);
252+
expect(scratch.textContent).to.equal("" + i);
252253
}
253254
});
255+
254256
it("should render static markup of a component", async () => {
255257
const count = signal(0);
256258

@@ -262,10 +264,13 @@ describe("@preact/signals-react", () => {
262264
</pre>
263265
);
264266
};
267+
268+
await render(<Test />);
269+
expect(scratch.textContent).to.equal("<code>0</code><code>0</code>");
270+
265271
for (let i = 0; i < 3; i++) {
266272
await act(async () => {
267273
count.value += 1;
268-
await render(<Test />);
269274
});
270275
expect(scratch.textContent).to.equal(
271276
`<code>${count.value}</code><code>${count.value}</code>`
@@ -282,7 +287,7 @@ describe("@preact/signals-react", () => {
282287
(state: number, action: number) => {
283288
return state + action;
284289
},
285-
1
290+
-2
286291
);
287292

288293
increment = () => dispatch(1);
@@ -295,23 +300,25 @@ describe("@preact/signals-react", () => {
295300
);
296301
};
297302

298-
let state = 1;
303+
await render(<Test />);
304+
expect(scratch.innerHTML).to.equal(
305+
"<pre><code>-2</code><code>0</code></pre>"
306+
);
307+
299308
for (let i = 0; i < 3; i++) {
300309
await act(async () => {
301310
count.value += 1;
302-
await render(<Test />);
303311
});
304312
expect(scratch.innerHTML).to.equal(
305-
`<pre><code>${state}</code><code>${count.value}</code></pre>`
313+
`<pre><code>-2</code><code>${count.value}</code></pre>`
306314
);
307315
}
308316

309317
await act(() => {
310318
increment();
311-
state += 1;
312319
});
313320
expect(scratch.innerHTML).to.equal(
314-
`<pre><code>${state}</code><code>${count.value}</code></pre>`
321+
`<pre><code>-1</code><code>${count.value}</code></pre>`
315322
);
316323
});
317324
});

0 commit comments

Comments
 (0)