@@ -8,6 +8,7 @@ import type { Options } from '../shared/options';
8
8
import { Preview } from '../shared/utils/preview' ;
9
9
import { Template } from '../shared/utils/template' ;
10
10
import { render } from './render' ;
11
+ import { withRenderOptions } from '../shared/with-render-options' ;
11
12
12
13
type Import = typeof import ( 'react-dom/server' ) & {
13
14
default : typeof import ( 'react-dom/server' ) ;
@@ -148,21 +149,36 @@ describe('render on the browser environment', () => {
148
149
await expect ( render ( element ) ) . rejects . toThrowErrorMatchingSnapshot ( ) ;
149
150
} ) ;
150
151
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
+ ) ;
151
159
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 ) ;
160
174
} ;
161
175
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
+ ) ;
165
180
166
- expect ( actualOutput ) . toMatchInlineSnapshot ( '"{"plainText":true}"' ) ;
181
+ const expectedOutput = '"{"id":"acbb4738-5a5e-4243-9b29-02cee9b8db57"}"' ;
182
+ expect ( actualOutput ) . toMatchInlineSnapshot ( expectedOutput ) ;
167
183
} ) ;
168
184
} ) ;
0 commit comments