@@ -458,16 +458,47 @@ describe('Table.Basic', () => {
458
458
expect ( wrapper . find ( 'tbody tr' ) . length ) . toBeTruthy ( ) ;
459
459
} ) ;
460
460
461
- it ( 'renders onRow correctly' , ( ) => {
462
- const onRow = ( record , index ) => ( {
463
- id : `row-${ record . key } ` ,
464
- index,
461
+ describe ( 'onRow' , ( ) => {
462
+ it ( 'renders onRow correctly' , ( ) => {
463
+ const onRow = ( record , index ) => ( {
464
+ id : `row-${ record . key } ` ,
465
+ index,
466
+ } ) ;
467
+ const wrapper = mount ( createTable ( { onRow } ) ) ;
468
+
469
+ expect ( wrapper . find ( 'tbody tr' ) . length ) . toBeTruthy ( ) ;
470
+ wrapper . find ( 'tbody tr' ) . forEach ( ( tr , index ) => {
471
+ expect ( tr . props ( ) . id ) . toEqual ( `row-${ data [ index ] . key } ` ) ;
472
+ } ) ;
465
473
} ) ;
466
- const wrapper = mount ( createTable ( { onRow } ) ) ;
467
474
468
- expect ( wrapper . find ( 'tbody tr' ) . length ) . toBeTruthy ( ) ;
469
- wrapper . find ( 'tbody tr' ) . forEach ( ( tr , index ) => {
470
- expect ( tr . props ( ) . id ) . toEqual ( `row-${ data [ index ] . key } ` ) ;
475
+ it ( 'onRow should keep update' , ( ) => {
476
+ const Test = ( ) => {
477
+ const [ count , setCount ] = React . useState ( 0 ) ;
478
+
479
+ return (
480
+ < div >
481
+ < Table
482
+ columns = { [ { dataIndex : 'key' } ] }
483
+ data = { [ { key : 0 } ] }
484
+ onRow = { ( ) => ( {
485
+ onClick ( ) {
486
+ setCount ( count + 1 ) ;
487
+ } ,
488
+ } ) }
489
+ />
490
+ < span id = "count" > { count } </ span >
491
+ </ div >
492
+ ) ;
493
+ } ;
494
+ const wrapper = mount ( < Test /> ) ;
495
+ for ( let i = 0 ; i < 10 ; i += 1 ) {
496
+ wrapper
497
+ . find ( 'tbody tr td' )
498
+ . last ( )
499
+ . simulate ( 'click' ) ;
500
+ expect ( wrapper . find ( '#count' ) . text ( ) ) . toEqual ( String ( i + 1 ) ) ;
501
+ }
471
502
} ) ;
472
503
} ) ;
473
504
0 commit comments