@@ -251,7 +251,7 @@ describe('react-most', () => {
251251 } )
252252 } )
253253
254- describe ( 'convension default to `action` field in sinks ' , ( ) => {
254+ describe ( 'ERROR ' , ( ) => {
255255 const Counter = connect ( intent$ => {
256256 return {
257257 sink$ : intent$ . map ( intent => {
@@ -263,7 +263,7 @@ describe('react-most', () => {
263263 }
264264 } ) ,
265265 actions : {
266- throwExeption : ( ) => ( { type : 'exception' } )
266+ throwExeption : ( ) => ( { type : 'exception' } ) ,
267267 } ,
268268 }
269269 } ) ( CounterView )
@@ -283,4 +283,47 @@ describe('react-most', () => {
283283 } )
284284 } )
285285 } )
286+
287+ describe ( 'unsubscribe when component unmounted' , ( ) => {
288+ it ( 'unsubscribe' , ( done ) => {
289+ const Counter = connect ( intent$ => {
290+ let incForever$ = most . periodic ( 100 , { type :'inc' } ) . map ( intent => {
291+ done . fail ( 'should not send intent any more' )
292+ return _ => _
293+ } )
294+ return {
295+ incForever$,
296+ sink$ : intent$ . map ( intent => {
297+ switch ( intent . type ) {
298+ case 'inc' :
299+ return state => ( { count :state . count + 1 } )
300+ default :
301+ return state => state
302+ }
303+ } )
304+ }
305+ } ) ( CounterView )
306+
307+ const TogglableMount = React . createClass ( {
308+ getInitialState ( ) {
309+ return {
310+ mount : true
311+ }
312+ } ,
313+ render ( ) {
314+ return this . state . mount && < Counter history = { true } />
315+ }
316+ } )
317+ spyOn ( console , 'error' )
318+ let counterWrapper = TestUtils . renderIntoDocument (
319+ < Most >
320+ < TogglableMount />
321+ </ Most >
322+ )
323+ let toggle = TestUtils . findRenderedComponentWithType ( counterWrapper , TogglableMount )
324+ let counter = TestUtils . findRenderedComponentWithType ( counterWrapper , Counter )
325+ toggle . setState ( { mount :false } )
326+ done ( )
327+ } )
328+ } )
286329} )
0 commit comments