@@ -4,6 +4,7 @@ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
4
4
import { signal , useComputed } from "@preact/signals-react" ;
5
5
import { createElement , useMemo , memo , StrictMode } from "react" ;
6
6
import { createRoot , Root } from "react-dom/client" ;
7
+ import { renderToStaticMarkup } from "react-dom/server" ;
7
8
import { act } from "react-dom/test-utils" ;
8
9
9
10
describe ( "@preact/signals-react" , ( ) => {
@@ -162,6 +163,26 @@ describe("@preact/signals-react", () => {
162
163
it ( "should consistently rerender in strict mode" , async ( ) => {
163
164
const sig = signal < string > ( null ! ) ;
164
165
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
+
165
186
const Test = memo ( ( ) => < p > { sig . value } </ p > ) ;
166
187
const App = ( ) => (
167
188
< StrictMode >
@@ -179,5 +200,26 @@ describe("@preact/signals-react", () => {
179
200
expect ( scratch . textContent ) . to . equal ( value ) ;
180
201
}
181
202
} ) ;
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
+ } ) ;
182
224
} ) ;
183
225
} ) ;
0 commit comments