@@ -86,6 +86,56 @@ describe('createStrictAPI()', () => {
86
86
87
87
expect ( getByTestId ( 'div' ) ) . toHaveCompiledCss ( 'all' , 'inherit' ) ;
88
88
} ) ;
89
+
90
+ it ( 'should type error with css properties not in the style scope' , ( ) => {
91
+ // NOTE: These are split into mutliple `css()` calls to ensure the type errors are not hidden
92
+ // as only one will error at a time when combined into one query
93
+
94
+ const bgStyles = css ( {
95
+ fontWeight : 'bold' , // just a valid property to ensure the `extends` keyword isn't working as intended
96
+ // @ts -expect-error - Object literal may only specify known properties, and 'bg' does not exist in type …
97
+ bg : 'red' ,
98
+ } ) ;
99
+
100
+ const colourStyles = css ( {
101
+ fontWeight : 'bold' , // just a valid property to ensure the `extends` keyword isn't working as intended
102
+ // @ts -expect-error - Object literal may only specify known properties, and 'colour' does not exist in type …
103
+ colour : 'var(--ds-text)' ,
104
+ } ) ;
105
+
106
+ const hoverStyles = css ( {
107
+ fontWeight : 'bold' , // just a valid property to ensure the `extends` keyword isn't working as intended
108
+ '&:hover' : {
109
+ fontWeight : 'bold' , // just a valid property to ensure the `extends` keyword isn't working as intended
110
+ // @ts -expect-error - Object literal may only specify known properties, and 'colour' does not exist in type …
111
+ colour : 'var(--ds-text-hover)' ,
112
+ } ,
113
+ } ) ;
114
+
115
+ const invalidPsuedoStyles = css ( {
116
+ fontWeight : 'bold' , // just a valid property to ensure the `extends` keyword isn't working as intended
117
+ // @ts -expect-error - bject literal may only specify known properties, and ''&:invalid-pseudo'' does not exist in type …
118
+ '&:invalid-pseudo' : {
119
+ color : 'var(--ds-text)' ,
120
+ } ,
121
+ } ) ;
122
+
123
+ const { getByTestId } = render (
124
+ < div css = { [ bgStyles , colourStyles , hoverStyles , invalidPsuedoStyles ] } data-testid = "div" />
125
+ ) ;
126
+
127
+ expect ( getByTestId ( 'div' ) ) . toHaveCompiledCss ( 'font-weight' , 'bold' ) ;
128
+ expect ( getByTestId ( 'div' ) ) . toHaveCompiledCss ( 'font-weight' , 'bold' , {
129
+ target : ':hover' ,
130
+ } ) ;
131
+
132
+ // These still get compiled to css, even if they're not valid
133
+ expect ( getByTestId ( 'div' ) ) . toHaveCompiledCss ( 'bg' , 'red' ) ;
134
+ expect ( getByTestId ( 'div' ) ) . toHaveCompiledCss ( 'colour' , 'var(--ds-text)' ) ;
135
+ expect ( getByTestId ( 'div' ) ) . toHaveCompiledCss ( 'colour' , 'var(--ds-text-hover)' , {
136
+ target : ':hover' ,
137
+ } ) ;
138
+ } ) ;
89
139
} ) ;
90
140
91
141
describe ( 'cssMap()' , ( ) => {
@@ -152,6 +202,72 @@ describe('createStrictAPI()', () => {
152
202
153
203
expect ( getByTestId ( 'div' ) ) . toHaveCompiledCss ( 'val' , 'ok' , { target : ':hover' } ) ;
154
204
} ) ;
205
+
206
+ it ( 'should type error with css properties not in the style scope' , ( ) => {
207
+ // NOTE: These are split into mutliple `css()` calls to ensure the type errors are not hidden
208
+ // as only one will error at a time when combined into one query
209
+
210
+ const bgStyles = cssMap ( {
211
+ primary : {
212
+ fontWeight : 'bold' , // just a valid property to ensure the `extends` keyword isn't working as intended
213
+ // @ts -expect-error - Object literal may only specify known properties, and 'bg' does not exist in type …
214
+ bg : 'red' ,
215
+ } ,
216
+ } ) ;
217
+
218
+ const colourStyles = cssMap ( {
219
+ primary : {
220
+ fontWeight : 'bold' , // just a valid property to ensure the `extends` keyword isn't working as intended
221
+ // @ts -expect-error - Object literal may only specify known properties, and 'colour' does not exist in type …
222
+ colour : 'var(--ds-text)' ,
223
+ } ,
224
+ } ) ;
225
+
226
+ const hoverStyles = cssMap ( {
227
+ primary : {
228
+ fontWeight : 'bold' , // just a valid property to ensure the `extends` keyword isn't working as intended
229
+ '&:hover' : {
230
+ fontWeight : 'bold' , // just a valid property to ensure the `extends` keyword isn't working as intended
231
+ // @ts -expect-error - Object literal may only specify known properties, and 'colour' does not exist in type …
232
+ colour : 'var(--ds-text-hover)' ,
233
+ } ,
234
+ } ,
235
+ } ) ;
236
+
237
+ const invalidPsuedoStyles = cssMap ( {
238
+ primary : {
239
+ fontWeight : 'bold' , // just a valid property to ensure the `extends` keyword isn't working as intended
240
+ // @ts -expect-error - bject literal may only specify known properties, and ''&:invalid-pseudo'' does not exist in type …
241
+ '&:invalid-pseudo' : {
242
+ color : 'var(--ds-text)' ,
243
+ } ,
244
+ } ,
245
+ } ) ;
246
+
247
+ const { getByTestId } = render (
248
+ < div
249
+ css = { [
250
+ bgStyles . primary ,
251
+ colourStyles . primary ,
252
+ hoverStyles . primary ,
253
+ invalidPsuedoStyles . primary ,
254
+ ] }
255
+ data-testid = "div"
256
+ />
257
+ ) ;
258
+
259
+ expect ( getByTestId ( 'div' ) ) . toHaveCompiledCss ( 'font-weight' , 'bold' ) ;
260
+ expect ( getByTestId ( 'div' ) ) . toHaveCompiledCss ( 'font-weight' , 'bold' , {
261
+ target : ':hover' ,
262
+ } ) ;
263
+
264
+ // These still get compiled to css, even if they're not valid
265
+ expect ( getByTestId ( 'div' ) ) . toHaveCompiledCss ( 'bg' , 'red' ) ;
266
+ expect ( getByTestId ( 'div' ) ) . toHaveCompiledCss ( 'colour' , 'var(--ds-text)' ) ;
267
+ expect ( getByTestId ( 'div' ) ) . toHaveCompiledCss ( 'colour' , 'var(--ds-text-hover)' , {
268
+ target : ':hover' ,
269
+ } ) ;
270
+ } ) ;
155
271
} ) ;
156
272
157
273
describe ( 'XCSSProp' , ( ) => {
0 commit comments