File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,15 @@ export default function Counter() {
2121 />
2222 < button className = "removeState" onClick = { ( ) => actions . removeState ( ) } />
2323 < button className = "asyncFunc" onClick = { actions . asyncFunc } />
24+ < button
25+ className = "compoundAsyncFunc"
26+ onClick = { async ( ) => {
27+ // Should set `state.count` = 256
28+ await actions . asyncFunc ( ) ;
29+ // Should set `state.count` = 257
30+ actions . increment ( ) ;
31+ } }
32+ />
2433 < input className = "googleStatus" value = { state . status } />
2534 < button className = "fetchGoogle" onClick = { actions . fetchGoogle } />
2635 </ div >
Original file line number Diff line number Diff line change @@ -158,6 +158,20 @@ it("can asyncFunc", async () => {
158158 } ) ;
159159} ) ;
160160
161+ it ( "can do compound async actions" , async ( ) => {
162+ const counter = TestRenderer . create ( < Counter /> ) ;
163+ const val = counter . root . findByProps ( { className : "val" } ) ;
164+ const button = counter . root . findByProps ( { className : "compoundAsyncFunc" } ) ;
165+
166+ await act ( async ( ) => {
167+ expect ( val . props . value ) . toBe ( 0 ) ;
168+
169+ await button . props . onClick ( ) ;
170+
171+ expect ( val . props . value ) . toBe ( 257 ) ;
172+ } ) ;
173+ } ) ;
174+
161175it ( "can fetchGoogle" , async ( ) => {
162176 const counter = TestRenderer . create ( < Counter /> ) ;
163177 const val = counter . root . findByProps ( { className : "googleStatus" } ) ;
You can’t perform that action at this time.
0 commit comments