File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -355,6 +355,44 @@ describe('useState', () => {
355355 expect ( renderSpy ) . to . be . calledThrice ;
356356 } ) ;
357357
358+ it ( 'Cancels effect invocations correctly when bailing' , ( ) => {
359+ const renderSpy = sinon . spy ( ) ;
360+ const cleanupSpy = sinon . spy ( ) ;
361+ const spy = sinon . spy ( ) ;
362+ let set ;
363+
364+ function App ( ) {
365+ const [ state , setState ] = useState ( 'initial' ) ;
366+ set = setState ;
367+
368+ renderSpy ( ) ;
369+ useEffect ( ( ) => {
370+ spy ( ) ;
371+ return ( ) => {
372+ cleanupSpy ( ) ;
373+ } ;
374+ } ) ;
375+ return < p > { state } </ p > ;
376+ }
377+
378+ act ( ( ) => {
379+ render ( < App /> , scratch ) ;
380+ } ) ;
381+
382+ expect ( renderSpy ) . to . be . calledOnce ;
383+ expect ( spy ) . to . be . calledOnce ;
384+ expect ( cleanupSpy ) . to . not . be . called ;
385+
386+ act ( ( ) => {
387+ set ( 'updated' ) ;
388+ set ( 'initial' ) ;
389+ } ) ;
390+
391+ expect ( renderSpy ) . to . be . calledTwice ;
392+ expect ( spy ) . to . be . calledOnce ;
393+ expect ( cleanupSpy ) . to . not . be . called ;
394+ } ) ;
395+
358396 // see preactjs/preact#3731
359397 it ( 'respects updates initiated from the parent' , ( ) => {
360398 let setChild , setParent ;
You can’t perform that action at this time.
0 commit comments