@@ -26,4 +26,130 @@ describe('Basic', () => {
2626 width : 100 ,
2727 } ) ;
2828 } ) ;
29+
30+ it ( 'Functionality of styled() should not trigger recompute when a runtime theme is not used' , ( ) => {
31+ const { styled, createTheme } = createStitches ( {
32+ theme : {
33+ sizes : { demoWidth : 100 } ,
34+ } ,
35+ } ) ;
36+
37+ const Comp = styled ( 'View' , {
38+ backgroundColor : 'red' ,
39+ height : 100 ,
40+ width : '$demoWidth' ,
41+ } ) ;
42+
43+ render ( < Comp /> ) ;
44+
45+ createTheme ( { sizes : { demoWidth : 10 } } ) ;
46+
47+ const { toJSON } = render ( < Comp /> ) ;
48+
49+ const result = toJSON ( ) ;
50+
51+ expect ( result ?. type ) . toEqual ( 'View' ) ;
52+ expect ( result ?. props . style [ 0 ] ) . toMatchObject ( {
53+ backgroundColor : 'red' ,
54+ height : 100 ,
55+ width : 100 ,
56+ } ) ;
57+ } ) ;
58+ } ) ;
59+
60+ describe ( 'Runtime' , ( ) => {
61+ it ( 'Functionality of ThemeProvider' , ( ) => {
62+ const { styled, createTheme, ThemeProvider } = createStitches ( {
63+ theme : {
64+ sizes : { demoWidth : 100 } ,
65+ } ,
66+ } ) ;
67+
68+ const Comp = styled ( 'View' , {
69+ backgroundColor : 'red' ,
70+ height : 100 ,
71+ width : '$demoWidth' ,
72+ } ) ;
73+
74+ const newTheme = createTheme ( { sizes : { demoWidth : 30 } } ) ;
75+
76+ const { toJSON } = render (
77+ < ThemeProvider theme = { newTheme } >
78+ < Comp />
79+ </ ThemeProvider >
80+ ) ;
81+
82+ const result = toJSON ( ) ;
83+
84+ expect ( result ?. type ) . toEqual ( 'View' ) ;
85+ expect ( result ?. props . style [ 0 ] ) . toMatchObject ( {
86+ backgroundColor : 'red' ,
87+ height : 100 ,
88+ width : 30 ,
89+ } ) ;
90+ } ) ;
91+
92+ it ( 'Functionality of ThemeProvider should use new theme when a runtime theme is added' , ( ) => {
93+ const { styled, createTheme, ThemeProvider } = createStitches ( {
94+ theme : {
95+ sizes : { demoWidth : 100 } ,
96+ } ,
97+ } ) ;
98+
99+ const Comp = styled ( 'View' , {
100+ backgroundColor : 'red' ,
101+ height : 100 ,
102+ width : '$demoWidth' ,
103+ } ) ;
104+
105+ const newTheme = createTheme ( { sizes : { demoWidth : 10 } } ) ;
106+
107+ const { toJSON } = render (
108+ < ThemeProvider theme = { newTheme } >
109+ < Comp />
110+ </ ThemeProvider >
111+ ) ;
112+
113+ const result = toJSON ( ) ;
114+
115+ expect ( result ?. type ) . toEqual ( 'View' ) ;
116+ expect ( result ?. props . style [ 0 ] ) . toMatchObject ( {
117+ backgroundColor : 'red' ,
118+ height : 100 ,
119+ width : 10 ,
120+ } ) ;
121+ } ) ;
122+
123+ it ( 'Functionality of ThemeProvider should trigger recompute when a runtime theme is added' , ( ) => {
124+ const { styled, createTheme, ThemeProvider } = createStitches ( {
125+ theme : {
126+ sizes : { demoWidth : 100 } ,
127+ } ,
128+ } ) ;
129+
130+ const Comp = styled ( 'View' , {
131+ backgroundColor : 'red' ,
132+ height : 100 ,
133+ width : '$demoWidth' ,
134+ } ) ;
135+
136+ render ( < Comp /> ) ;
137+
138+ const newTheme = createTheme ( { sizes : { demoWidth : 10 } } ) ;
139+
140+ const { toJSON } = render (
141+ < ThemeProvider theme = { newTheme } >
142+ < Comp />
143+ </ ThemeProvider >
144+ ) ;
145+
146+ const result = toJSON ( ) ;
147+
148+ expect ( result ?. type ) . toEqual ( 'View' ) ;
149+ expect ( result ?. props . style [ 0 ] ) . toMatchObject ( {
150+ backgroundColor : 'red' ,
151+ height : 100 ,
152+ width : 10 ,
153+ } ) ;
154+ } ) ;
29155} ) ;
0 commit comments