@@ -183,15 +183,15 @@ describe('serverRenderReactComponent', () => {
183183 await expect ( renderResult . then ( ( r ) => r . hasErrors ) ) . resolves . toBeFalsy ( ) ;
184184 } ) ;
185185
186- // When an async render function returns an object, serverRenderReactComponent will return the object as is .
187- // It does not validate properties like renderedHtml or hasErrors; it simply returns the object.
186+ // When an async render function returns an object, serverRenderReactComponent will return the object as it after stringifying it .
187+ // It does not validate properties like renderedHtml or hasErrors; it simply returns the stringified object.
188188 // This behavior can cause issues with the ruby_on_rails gem.
189189 // To avoid such issues, ensure that the returned object includes a `componentHtml` property and use the `react_component_hash` helper.
190190 // This is demonstrated in the "can render async render function used with react_component_hash helper" test.
191191 it ( 'serverRenderReactComponent returns the object returned by the async render function' , async ( ) => {
192- const expectedHtml = '<div>Hello</div>' ;
192+ const resultObject = { renderedHtml : '<div>Hello</div>' } ;
193193 const X6 = ( ( _props : unknown , _railsContext ?: RailsContext ) : Promise < ServerRenderResult > =>
194- Promise . resolve ( { renderedHtml : expectedHtml } ) ) as RenderFunction ;
194+ Promise . resolve ( resultObject ) ) as RenderFunction ;
195195
196196 ComponentRegistry . register ( { X6 } ) ;
197197
@@ -205,16 +205,16 @@ describe('serverRenderReactComponent', () => {
205205
206206 const renderResult = serverRenderReactComponent ( renderParams ) ;
207207 assertIsPromise ( renderResult ) ;
208- const html = ( await renderResult . then ( ( r ) => r . html ) ) as ServerRenderResult ;
209- expectMatchObject ( html , { renderedHtml : expectedHtml } ) ;
208+ const html = await renderResult . then ( ( r ) => r . html ) ;
209+ expect ( html ) . toEqual ( JSON . stringify ( resultObject ) ) ;
210210 } ) ;
211211
212212 // Because the object returned by the async render function is returned as it is,
213213 // we can make the async render function returns an object with `componentHtml` property.
214214 // This is useful when we want to render a component using the `react_component_hash` helper.
215215 it ( 'can render async render function used with react_component_hash helper' , async ( ) => {
216- const X7 = ( _props : unknown , _railsContext ?: RailsContext ) =>
217- Promise . resolve ( { componentHtml : '<div>Hello</div>' } ) ;
216+ const reactComponentHashResult = { componentHtml : '<div>Hello</div>' } ;
217+ const X7 = ( _props : unknown , _railsContext ?: RailsContext ) => Promise . resolve ( reactComponentHashResult ) ;
218218
219219 ComponentRegistry . register ( { X7 : X7 as unknown as RenderFunction } ) ;
220220
@@ -229,7 +229,7 @@ describe('serverRenderReactComponent', () => {
229229 const renderResult = serverRenderReactComponent ( renderParams ) ;
230230 assertIsPromise ( renderResult ) ;
231231 const result = await renderResult ;
232- expect ( result . html ) . toMatchObject ( { componentHtml : '<div>Hello</div>' } ) ;
232+ expect ( result . html ) . toEqual ( JSON . stringify ( reactComponentHashResult ) ) ;
233233 } ) ;
234234
235235 it ( 'serverRenderReactComponent renders an error if attempting to render a renderer' , ( ) => {
0 commit comments