@@ -18,6 +18,10 @@ describe('linkClass', () => {
18
18
expect ( linkClass ( < div > < p /> </ div > ) ) . to . deep . equal ( < div > < p /> </ div > ) ;
19
19
} ) ;
20
20
21
+ it ( 'does not affect element properties with a single element child in non-`children` prop' , ( ) => {
22
+ expect ( linkClass ( < div el = { < p /> } /> ) ) . to . deep . equal ( < div el = { < p /> } /> ) ;
23
+ } ) ;
24
+
21
25
it ( 'does not affect element properties with a single text child' , ( ) => {
22
26
expect ( linkClass ( < div > test</ div > ) ) . to . deep . equal ( < div > test</ div > ) ;
23
27
} ) ;
@@ -81,6 +85,26 @@ describe('linkClass', () => {
81
85
expect ( subject . props . children . props . className ) . to . equal ( 'foo-1' ) ;
82
86
} ) ;
83
87
} ) ;
88
+ context ( 'when a descendant element in non-`children` prop has styleName' , ( ) => {
89
+ it ( 'assigns a generated className' , ( ) => {
90
+ let subject ;
91
+
92
+ subject = < div
93
+ el = { < p styleName = 'foo' /> }
94
+ els = { [ < p key = 'bar' styleName = 'bar' /> , [ < p key = 'baz' styleName = 'baz' /> ] ] }
95
+ /> ;
96
+
97
+ subject = linkClass ( subject , {
98
+ bar : 'bar-1' ,
99
+ baz : 'baz-1' ,
100
+ foo : 'foo-1'
101
+ } ) ;
102
+
103
+ expect ( subject . props . el . props . className ) . to . equal ( 'foo-1' ) ;
104
+ expect ( subject . props . els [ 0 ] . props . className ) . to . equal ( 'bar-1' ) ;
105
+ expect ( subject . props . els [ 1 ] [ 0 ] . props . className ) . to . equal ( 'baz-1' ) ;
106
+ } ) ;
107
+ } ) ;
84
108
context ( 'when multiple descendant elements have styleName' , ( ) => {
85
109
it ( 'assigns a generated className' , ( ) => {
86
110
let subject ;
@@ -139,6 +163,32 @@ describe('linkClass', () => {
139
163
expect ( subject . props . children [ 1 ] . props . className ) . to . equal ( 'bar-1' ) ;
140
164
} ) ;
141
165
} ) ;
166
+ context ( 'when non-`children` prop is an iterable' , ( ) => {
167
+ it ( 'it is left untouched' , ( ) => {
168
+ let subject ;
169
+
170
+ const iterable = {
171
+ 0 : < p key = '1' styleName = 'foo' /> ,
172
+ 1 : < p key = '2' styleName = 'bar' /> ,
173
+ length : 2 ,
174
+
175
+ // eslint-disable-next-line no-use-extend-native/no-use-extend-native
176
+ [ Symbol . iterator ] : Array . prototype [ Symbol . iterator ]
177
+ } ;
178
+
179
+ subject = < div els = { iterable } /> ;
180
+
181
+ subject = linkClass ( subject , {
182
+ bar : 'bar-1' ,
183
+ foo : 'foo-1'
184
+ } ) ;
185
+
186
+ expect ( subject . props . els [ 0 ] . props . styleName ) . to . equal ( 'foo' ) ;
187
+ expect ( subject . props . els [ 1 ] . props . styleName ) . to . equal ( 'bar' ) ;
188
+ expect ( subject . props . els [ 0 ] . props ) . not . to . have . property ( 'className' ) ;
189
+ expect ( subject . props . els [ 1 ] . props ) . not . to . have . property ( 'className' ) ;
190
+ } ) ;
191
+ } ) ;
142
192
context ( 'when ReactElement does not have an existing className' , ( ) => {
143
193
it ( 'uses the generated class name to set the className property' , ( ) => {
144
194
let subject ;
@@ -277,24 +327,35 @@ describe('linkClass', () => {
277
327
it ( 'deletes styleName property from the target element (deep)' , ( ) => {
278
328
let subject ;
279
329
280
- subject = < div styleName = 'foo' >
330
+ subject = < div
331
+ el = { < span styleName = 'baz' /> }
332
+ els = { [ < span key = 'foo' styleName = 'foo' /> , [ < span key = 'bar' styleName = 'bar' /> ] ] }
333
+ styleName = 'foo'
334
+ >
281
335
< div styleName = 'bar' />
282
336
< div styleName = 'bar' />
283
337
</ div > ;
284
338
285
339
subject = linkClass ( subject , {
286
340
bar : 'bar-1' ,
341
+ baz : 'baz-1' ,
287
342
foo : 'foo-1'
288
343
} ) ;
289
344
290
345
expect ( subject . props . children [ 0 ] . props . className ) . to . deep . equal ( 'bar-1' ) ;
291
346
expect ( subject . props . children [ 0 ] . props ) . not . to . have . property ( 'styleName' ) ;
347
+ expect ( subject . props . el . props . className ) . to . deep . equal ( 'baz-1' ) ;
348
+ expect ( subject . props . el . props ) . not . to . have . property ( 'styleName' ) ;
349
+ expect ( subject . props . els [ 0 ] . props . className ) . to . deep . equal ( 'foo-1' ) ;
350
+ expect ( subject . props . els [ 0 ] . props ) . not . to . have . property ( 'styleName' ) ;
351
+ expect ( subject . props . els [ 1 ] [ 0 ] . props . className ) . to . deep . equal ( 'bar-1' ) ;
352
+ expect ( subject . props . els [ 1 ] [ 0 ] . props ) . not . to . have . property ( 'styleName' ) ;
292
353
} ) ;
293
354
294
355
it ( 'does not change defined keys of children if there are multiple children' , ( ) => {
295
356
let subject ;
296
357
297
- subject = < div >
358
+ subject = < div els = { [ < span key = 'foo' /> , < span key = 'bar' /> ] } >
298
359
< span key = 'foo' />
299
360
< span key = 'bar' />
300
361
</ div > ;
@@ -303,5 +364,7 @@ describe('linkClass', () => {
303
364
304
365
expect ( subject . props . children [ 0 ] . key ) . to . equal ( 'foo' ) ;
305
366
expect ( subject . props . children [ 1 ] . key ) . to . equal ( 'bar' ) ;
367
+ expect ( subject . props . els [ 0 ] . key ) . to . equal ( 'foo' ) ;
368
+ expect ( subject . props . els [ 1 ] . key ) . to . equal ( 'bar' ) ;
306
369
} ) ;
307
370
} ) ;
0 commit comments