@@ -2,6 +2,7 @@ import React from 'react';
2
2
import { expect } from 'chai' ;
3
3
4
4
import {
5
+ delay ,
5
6
describeIf ,
6
7
itIf ,
7
8
} from '../../_helpers' ;
@@ -122,5 +123,50 @@ export default function describeProps({
122
123
} ) ;
123
124
} ) ;
124
125
} ) ;
126
+
127
+ describe ( 'props in async handler' , ( ) => {
128
+ class TestComponent extends React . Component {
129
+ constructor ( props ) {
130
+ super ( props ) ;
131
+ this . state = { counter : 1 } ;
132
+ this . handleClick = this . handleClick . bind ( this ) ;
133
+ }
134
+
135
+ handleClick ( ) {
136
+ return delay ( 100 ) . then ( ( ) => new Promise ( ( resolve ) => {
137
+ this . setState ( { counter : 2 } , ( ) => {
138
+ resolve ( ) ;
139
+ } ) ;
140
+ } ) ) ;
141
+ }
142
+
143
+ render ( ) {
144
+ const { counter } = this . state ;
145
+ return (
146
+ < div id = "parentDiv" onClick = { this . handleClick } >
147
+ < TestSubComponent id = "childDiv" counter = { counter } />
148
+ </ div >
149
+ ) ;
150
+ }
151
+ }
152
+
153
+ class TestSubComponent extends React . Component {
154
+ render ( ) {
155
+ const { counter } = this . props ;
156
+ return < div > { counter } </ div > ;
157
+ }
158
+ }
159
+
160
+ it ( 'child component props should update after call to setState in async handler' , ( ) => {
161
+ const wrapper = Wrap ( < TestComponent /> ) ;
162
+ expect ( wrapper . find ( TestSubComponent ) . props ( ) ) . to . eql ( { id : 'childDiv' , counter : 1 } ) ;
163
+ const promise = wrapper . find ( '#parentDiv' ) . props ( ) . onClick ( ) ;
164
+ expect ( wrapper . find ( TestSubComponent ) . props ( ) ) . to . eql ( { id : 'childDiv' , counter : 1 } ) ;
165
+ return promise . then ( ( ) => {
166
+ wrapper . update ( ) ;
167
+ expect ( wrapper . find ( TestSubComponent ) . props ( ) ) . to . eql ( { id : 'childDiv' , counter : 2 } ) ;
168
+ } ) ;
169
+ } ) ;
170
+ } ) ;
125
171
} ) ;
126
172
}
0 commit comments