@@ -8,6 +8,7 @@ import type { Options } from '../shared/options';
88import { Preview } from '../shared/utils/preview' ;
99import { Template } from '../shared/utils/template' ;
1010import { render } from './render' ;
11+ import { withRenderOptions } from '../shared/with-render-options' ;
1112
1213type Import = typeof import ( 'react-dom/server' ) & {
1314 default : typeof import ( 'react-dom/server' ) ;
@@ -148,21 +149,36 @@ describe('render on the browser environment', () => {
148149 await expect ( render ( element ) ) . rejects . toThrowErrorMatchingSnapshot ( ) ;
149150 } ) ;
150151
152+ it ( 'passes render options to components wrapped with withRenderOptions' , async ( ) => {
153+ type TemplateWithOptionsProps = { id : string } ;
154+ const TemplateWithOptions = withRenderOptions < TemplateWithOptionsProps > (
155+ ( props ) => {
156+ return JSON . stringify ( props ) ;
157+ } ,
158+ ) ;
151159
152- it ( 'passes render options to the rendered component' , async ( ) => {
153- type TemplateWithOptionsProps = {
154- reactEmailRenderOptions ?: Options ;
155- } ;
156- const TemplateWithOptions = ( {
157- reactEmailRenderOptions,
158- } : TemplateWithOptionsProps ) => {
159- return JSON . stringify ( reactEmailRenderOptions ) ;
160+ const actualOutput = await render (
161+ < TemplateWithOptions id = "acbb4738-5a5e-4243-9b29-02cee9b8db57" /> ,
162+ { plainText : true } ,
163+ ) ;
164+
165+ const expectedOutput =
166+ '"{"id":"acbb4738-5a5e-4243-9b29-02cee9b8db57","renderOptions":{"plainText":true}}"' ;
167+ expect ( actualOutput ) . toMatchInlineSnapshot ( expectedOutput ) ;
168+ } ) ;
169+
170+ it ( 'does not pass render options to components not wrapped with withRenderOptions' , async ( ) => {
171+ type TemplateWithOptionsProps = { id : string } ;
172+ const TemplateWithOptions = ( props : TemplateWithOptionsProps ) => {
173+ return JSON . stringify ( props ) ;
160174 } ;
161175
162- const actualOutput = await render ( < TemplateWithOptions /> , {
163- plainText : true ,
164- } ) ;
176+ const actualOutput = await render (
177+ < TemplateWithOptions id = "acbb4738-5a5e-4243-9b29-02cee9b8db57" /> ,
178+ { plainText : true } ,
179+ ) ;
165180
166- expect ( actualOutput ) . toMatchInlineSnapshot ( '"{"plainText":true}"' ) ;
181+ const expectedOutput = '"{"id":"acbb4738-5a5e-4243-9b29-02cee9b8db57"}"' ;
182+ expect ( actualOutput ) . toMatchInlineSnapshot ( expectedOutput ) ;
167183 } ) ;
168184} ) ;
0 commit comments