@@ -24,10 +24,8 @@ describe('ReactCoroutine', () => {
2424 } ) ;
2525
2626 it ( 'should render a coroutine' , ( ) => {
27-
2827 var ops = [ ] ;
2928
30-
3129 function Continuation ( { isSame } ) {
3230 ops . push ( [ 'Continuation' , isSame ] ) ;
3331 return < span > { isSame ? 'foo==bar' : 'foo!=bar' } </ span > ;
@@ -84,7 +82,72 @@ describe('ReactCoroutine', () => {
8482 [ 'Continuation' , true ] ,
8583 [ 'Continuation' , false ] ,
8684 ] ) ;
87-
8885 } ) ;
8986
87+ it ( 'should unmount a composite in a coroutine' , ( ) => {
88+ var ops = [ ] ;
89+
90+ class Continuation extends React . Component {
91+ render ( ) {
92+ ops . push ( 'Continuation' ) ;
93+ return < div /> ;
94+ }
95+ componentWillUnmount ( ) {
96+ ops . push ( 'Unmount Continuation' ) ;
97+ }
98+ }
99+
100+ class Child extends React . Component {
101+ render ( ) {
102+ ops . push ( 'Child' ) ;
103+ return ReactCoroutine . createYield ( { } , Continuation , null ) ;
104+ }
105+ componentWillUnmount ( ) {
106+ ops . push ( 'Unmount Child' ) ;
107+ }
108+ }
109+
110+ function HandleYields ( props , yields ) {
111+ ops . push ( 'HandleYields' ) ;
112+ return yields . map ( y => < y . continuation /> ) ;
113+ }
114+
115+ class Parent extends React . Component {
116+ render ( ) {
117+ ops . push ( 'Parent' ) ;
118+ return ReactCoroutine . createCoroutine (
119+ this . props . children ,
120+ HandleYields ,
121+ this . props
122+ ) ;
123+ }
124+ componentWillUnmount ( ) {
125+ ops . push ( 'Unmount Parent' ) ;
126+ }
127+ }
128+
129+ ReactNoop . render ( < Parent > < Child /> </ Parent > ) ;
130+ ReactNoop . flush ( ) ;
131+
132+ expect ( ops ) . toEqual ( [
133+ 'Parent' ,
134+ 'Child' ,
135+ 'HandleYields' ,
136+ 'Continuation' ,
137+ ] ) ;
138+
139+ ops = [ ] ;
140+
141+ ReactNoop . render ( < div /> ) ;
142+ ReactNoop . flush ( ) ;
143+
144+ expect ( ops ) . toEqual ( [
145+ 'Unmount Parent' ,
146+ // TODO: This should happen in the order Child, Continuation which it
147+ // will once we swap stateNode and child positions of these.
148+ 'Unmount Continuation' ,
149+ 'Unmount Child' ,
150+ ] ) ;
151+
152+ } ) ;
90153} ) ;
0 commit comments