File tree Expand file tree Collapse file tree 3 files changed +57
-3
lines changed Expand file tree Collapse file tree 3 files changed +57
-3
lines changed Original file line number Diff line number Diff line change @@ -2056,9 +2056,12 @@ describe('shallow', () => {
2056
2056
}
2057
2057
}
2058
2058
const wrapper = shallow ( < MyComponent /> , { disableLifecycleMethods : true } ) ;
2059
- expect ( wrapper . find ( Table ) . length ) . to . equal ( 0 ) ;
2059
+ expect ( wrapper . find ( Table ) ) . to . have . lengthOf ( 0 ) ;
2060
+
2060
2061
wrapper . instance ( ) . componentDidMount ( ) ;
2061
- expect ( wrapper . find ( Table ) . length ) . to . equal ( 1 ) ;
2062
+ // wrapper.update(); // TODO: uncomment or delete
2063
+
2064
+ expect ( wrapper . find ( Table ) ) . to . have . lengthOf ( 1 ) ;
2062
2065
} ) ;
2063
2066
2064
2067
it ( 'calls shouldComponentUpdate when disableLifecycleMethods flag is true' , ( ) => {
Original file line number Diff line number Diff line change @@ -293,6 +293,50 @@ export default function describeFind({
293
293
expect ( wrapper . find ( '.b' ) . find ( '.c' ) ) . to . have . lengthOf ( 6 ) ;
294
294
} ) ;
295
295
296
+ it ( 'can call find on the same wrapper more than once' , ( ) => {
297
+ class TestComponent extends React . Component {
298
+ render ( ) {
299
+ return (
300
+ < div >
301
+ < h1 > Title</ h1 >
302
+ < span key = "1" > 1</ span >
303
+ < span key = "2" > 2</ span >
304
+ </ div >
305
+ ) ;
306
+ }
307
+ }
308
+ const component = Wrap ( < TestComponent /> ) ;
309
+
310
+ const cards = component . find ( 'span' ) ;
311
+
312
+ const title = component . find ( 'h1' ) ; // for side effects
313
+ expect ( title . is ( 'h1' ) ) . to . equal ( true ) ;
314
+
315
+ expect ( cards . at ( 0 ) . parent ( ) . is ( 'div' ) ) . to . equal ( true ) ;
316
+ } ) ;
317
+
318
+ describeIf ( is ( '> 0.13' ) , 'stateless function components (SFCs)' , ( ) => {
319
+ it ( 'can call find on the same wrapper more than once' , ( ) => {
320
+ function TestComponentSFC ( ) {
321
+ return (
322
+ < div >
323
+ < h1 > Title</ h1 >
324
+ < span key = "1" > 1</ span >
325
+ < span key = "2" > 2</ span >
326
+ </ div >
327
+ ) ;
328
+ }
329
+ const component = Wrap ( < TestComponentSFC /> ) ;
330
+
331
+ const cards = component . find ( 'span' ) ;
332
+
333
+ const title = component . find ( 'h1' ) ; // for side effects
334
+ expect ( title . is ( 'h1' ) ) . to . equal ( true ) ;
335
+
336
+ expect ( cards . at ( 0 ) . parent ( ) . debug ( ) ) . to . equal ( '<div />' ) ;
337
+ } ) ;
338
+ } ) ;
339
+
296
340
it ( 'works with an adjacent sibling selector' , ( ) => {
297
341
const a = 'some' ;
298
342
const b = 'text' ;
Original file line number Diff line number Diff line change @@ -460,8 +460,13 @@ class ShallowWrapper {
460
460
*/
461
461
getNodesInternal ( ) {
462
462
if ( this [ ROOT ] === this && this . length === 1 ) {
463
- this . update ( ) ;
463
+ const adapter = getAdapter ( this [ OPTIONS ] ) ;
464
+ const prevProps = ( this [ UNRENDERED ] && this [ UNRENDERED ] . props ) || { } ;
465
+ if ( ! adapter . shouldUpdateComponent || adapter . shouldUpdateComponent ( prevProps , this [ ROOT ] ) ) {
466
+ this . update ( ) ;
467
+ }
464
468
}
469
+
465
470
return this [ NODES ] ;
466
471
}
467
472
@@ -556,8 +561,10 @@ class ShallowWrapper {
556
561
*/
557
562
unmount ( ) {
558
563
this [ RENDERER ] . unmount ( ) ;
564
+ this . update ( ) ;
559
565
if ( this [ ROOT ] [ WRAPPING_COMPONENT ] ) {
560
566
this [ ROOT ] [ WRAPPING_COMPONENT ] . unmount ( ) ;
567
+ this [ ROOT ] [ WRAPPING_COMPONENT ] . update ( ) ;
561
568
}
562
569
return this ;
563
570
}
You can’t perform that action at this time.
0 commit comments