@@ -25,11 +25,14 @@ function generateWithThemeRenderer(
25
25
jsonFile : string ,
26
26
renderConfig : ReactRenderConfig = { } ,
27
27
options ?: ReactThemeStudioTemplateRendererOptions ,
28
- ) : string {
28
+ ) {
29
29
const rendererFactory = new StudioTemplateRendererFactory (
30
30
( theme : StudioTheme ) => new ReactThemeStudioTemplateRenderer ( theme , renderConfig , options ) ,
31
31
) ;
32
- return rendererFactory . buildRenderer ( loadSchemaFromJSONFile ( jsonFile ) ) . renderComponent ( ) . componentText ;
32
+ const { componentText, declaration } = rendererFactory
33
+ . buildRenderer ( loadSchemaFromJSONFile ( jsonFile ) )
34
+ . renderComponent ( ) ;
35
+ return { componentText, declaration } ;
33
36
}
34
37
35
38
function generateThemeObject ( jsonFile : string ) : any {
@@ -46,19 +49,28 @@ function generateThemeObject(jsonFile: string): any {
46
49
describe ( 'react theme renderer tests' , ( ) => {
47
50
describe ( 'theme' , ( ) => {
48
51
it ( 'should render the theme' , ( ) => {
49
- expect ( generateWithThemeRenderer ( 'theme' ) ) . toMatchSnapshot ( ) ;
52
+ expect ( generateWithThemeRenderer ( 'theme' ) . componentText ) . toMatchSnapshot ( ) ;
50
53
} ) ;
51
54
52
55
it ( 'should render the theme with TSX' , ( ) => {
53
- expect ( generateWithThemeRenderer ( 'theme' , { script : ScriptKind . TSX } ) ) . toMatchSnapshot ( ) ;
56
+ const { componentText, declaration } = generateWithThemeRenderer ( 'theme' , { script : ScriptKind . TSX } ) ;
57
+ expect ( componentText ) . toMatchSnapshot ( ) ;
58
+ expect ( declaration ) . toBeUndefined ( ) ;
54
59
} ) ;
55
60
56
61
it ( 'should render the theme with ES5' , ( ) => {
57
- expect ( generateWithThemeRenderer ( 'theme' , { target : ScriptTarget . ES5 , script : ScriptKind . JS } ) ) . toMatchSnapshot ( ) ;
62
+ const { componentText, declaration } = generateWithThemeRenderer ( 'theme' , {
63
+ target : ScriptTarget . ES5 ,
64
+ script : ScriptKind . JS ,
65
+ renderTypeDeclarations : true ,
66
+ } ) ;
67
+ expect ( componentText ) . toMatchSnapshot ( ) ;
68
+ expect ( declaration ) . toBeDefined ( ) ;
69
+ expect ( declaration ) . toMatchSnapshot ( ) ;
58
70
} ) ;
59
71
60
72
it ( 'should render the default theme' , ( ) => {
61
- expect ( generateWithThemeRenderer ( 'theme' , { } , { renderDefaultTheme : true } ) ) . toMatchSnapshot ( ) ;
73
+ expect ( generateWithThemeRenderer ( 'theme' , { } , { renderDefaultTheme : true } ) . componentText ) . toMatchSnapshot ( ) ;
62
74
} ) ;
63
75
} ) ;
64
76
0 commit comments