File tree 3 files changed +57
-3
lines changed
3 files changed +57
-3
lines changed Original file line number Diff line number Diff line change @@ -2237,9 +2237,12 @@ describe('shallow', () => {
2237
2237
}
2238
2238
}
2239
2239
const wrapper = shallow ( < MyComponent /> , { disableLifecycleMethods : true } ) ;
2240
- expect ( wrapper . find ( Table ) . length ) . to . equal ( 0 ) ;
2240
+ expect ( wrapper . find ( Table ) ) . to . have . lengthOf ( 0 ) ;
2241
+
2241
2242
wrapper . instance ( ) . componentDidMount ( ) ;
2242
- expect ( wrapper . find ( Table ) . length ) . to . equal ( 1 ) ;
2243
+ // wrapper.update(); // TODO: uncomment or delete
2244
+
2245
+ expect ( wrapper . find ( Table ) ) . to . have . lengthOf ( 1 ) ;
2243
2246
} ) ;
2244
2247
2245
2248
it ( 'calls shouldComponentUpdate when disableLifecycleMethods flag is true' , ( ) => {
Original file line number Diff line number Diff line change @@ -308,6 +308,50 @@ export default function describeFind({
308
308
expect ( wrapper . find ( '.b' ) . find ( '.c' ) ) . to . have . lengthOf ( 6 ) ;
309
309
} ) ;
310
310
311
+ it ( 'can call find on the same wrapper more than once' , ( ) => {
312
+ class TestComponent extends React . Component {
313
+ render ( ) {
314
+ return (
315
+ < div >
316
+ < h1 > Title</ h1 >
317
+ < span key = "1" > 1</ span >
318
+ < span key = "2" > 2</ span >
319
+ </ div >
320
+ ) ;
321
+ }
322
+ }
323
+ const component = Wrap ( < TestComponent /> ) ;
324
+
325
+ const cards = component . find ( 'span' ) ;
326
+
327
+ const title = component . find ( 'h1' ) ; // for side effects
328
+ expect ( title . is ( 'h1' ) ) . to . equal ( true ) ;
329
+
330
+ expect ( cards . at ( 0 ) . parent ( ) . is ( 'div' ) ) . to . equal ( true ) ;
331
+ } ) ;
332
+
333
+ describeIf ( is ( '> 0.13' ) , 'stateless function components (SFCs)' , ( ) => {
334
+ it ( 'can call find on the same wrapper more than once' , ( ) => {
335
+ function TestComponentSFC ( ) {
336
+ return (
337
+ < div >
338
+ < h1 > Title</ h1 >
339
+ < span key = "1" > 1</ span >
340
+ < span key = "2" > 2</ span >
341
+ </ div >
342
+ ) ;
343
+ }
344
+ const component = Wrap ( < TestComponentSFC /> ) ;
345
+
346
+ const cards = component . find ( 'span' ) ;
347
+
348
+ const title = component . find ( 'h1' ) ; // for side effects
349
+ expect ( title . is ( 'h1' ) ) . to . equal ( true ) ;
350
+
351
+ expect ( cards . at ( 0 ) . parent ( ) . debug ( ) ) . to . equal ( '<div />' ) ;
352
+ } ) ;
353
+ } ) ;
354
+
311
355
it ( 'works with an adjacent sibling selector' , ( ) => {
312
356
const a = 'some' ;
313
357
const b = 'text' ;
Original file line number Diff line number Diff line change @@ -473,8 +473,13 @@ class ShallowWrapper {
473
473
*/
474
474
getNodesInternal ( ) {
475
475
if ( this [ ROOT ] === this && this . length === 1 ) {
476
- this . update ( ) ;
476
+ const adapter = getAdapter ( this [ OPTIONS ] ) ;
477
+ const prevProps = ( this [ UNRENDERED ] && this [ UNRENDERED ] . props ) || { } ;
478
+ if ( ! adapter . shouldComponentUpdate || adapter . shouldComponentUpdate ( prevProps , this [ ROOT ] ) ) {
479
+ this . update ( ) ;
480
+ }
477
481
}
482
+
478
483
return this [ NODES ] ;
479
484
}
480
485
@@ -569,8 +574,10 @@ class ShallowWrapper {
569
574
*/
570
575
unmount ( ) {
571
576
this [ RENDERER ] . unmount ( ) ;
577
+ this . update ( ) ;
572
578
if ( this [ ROOT ] [ WRAPPING_COMPONENT ] ) {
573
579
this [ ROOT ] [ WRAPPING_COMPONENT ] . unmount ( ) ;
580
+ this [ ROOT ] [ WRAPPING_COMPONENT ] . update ( ) ;
574
581
}
575
582
return this ;
576
583
}
You can’t perform that action at this time.
0 commit comments