File tree Expand file tree Collapse file tree 2 files changed +22
-9
lines changed
Expand file tree Collapse file tree 2 files changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -68,15 +68,12 @@ export default class Async extends Component {
6868 }
6969 }
7070
71- componentWillUpdate ( nextProps , nextState ) {
72- const propertiesToSync = [ 'options' ] ;
73- propertiesToSync . forEach ( ( prop ) => {
74- if ( this . props [ prop ] !== nextProps [ prop ] ) {
75- this . setState ( {
76- [ prop ] : nextProps [ prop ]
77- } ) ;
78- }
79- } ) ;
71+ componentWillReceiveProps ( nextProps ) {
72+ if ( nextProps . options !== this . props . options ) {
73+ this . setState ( {
74+ options : nextProps . options ,
75+ } ) ;
76+ }
8077 }
8178
8279 clearOptions ( ) {
Original file line number Diff line number Diff line change @@ -447,4 +447,20 @@ describe('Async', () => {
447447 expect ( input , 'to equal' , document . activeElement ) ;
448448 } ) ;
449449 } ) ;
450+
451+
452+ describe ( 'props sync test' , ( ) => {
453+ it ( 'should update options on componentWillReceiveProps' , ( ) => {
454+ createControl ( {
455+ } ) ;
456+ asyncInstance . componentWillReceiveProps ( {
457+ options : [ {
458+ label : 'bar' ,
459+ value : 'foo' ,
460+ } ]
461+ } ) ;
462+ expect ( asyncNode . querySelectorAll ( '[role=option]' ) . length , 'to equal' , 1 ) ;
463+ expect ( asyncNode . querySelector ( '[role=option]' ) . textContent , 'to equal' , 'bar' ) ;
464+ } ) ;
465+ } ) ;
450466} ) ;
You can’t perform that action at this time.
0 commit comments