11import { expect } from 'chai' ;
22import * as Rx from '../../dist/cjs/Rx' ;
3- import { DoneSignature } from '../helpers/test-helper' ;
43declare const { hot, cold, asDiagram, expectObservable, expectSubscriptions} ;
54
65const Observable = Rx . Observable ;
@@ -344,7 +343,7 @@ describe('Observable.prototype.bufferToggle', () => {
344343 expectSubscriptions ( e2 . subscriptions ) . toBe ( e2subs ) ;
345344 } ) ;
346345
347- it ( 'should accept closing selector that returns a resolved promise' , ( done : DoneSignature ) => {
346+ it ( 'should accept closing selector that returns a resolved promise' , ( done : MochaDone ) => {
348347 const e1 = Observable . concat ( Observable . of ( 1 ) ,
349348 Observable . timer ( 10 ) . mapTo ( 2 ) ,
350349 Observable . timer ( 10 ) . mapTo ( 3 ) ,
@@ -354,15 +353,16 @@ describe('Observable.prototype.bufferToggle', () => {
354353
355354 e1 . bufferToggle ( Observable . of ( 10 ) , ( ) => new Promise ( ( resolve : any ) => { resolve ( 42 ) ; } ) )
356355 . subscribe ( ( x ) => {
357- expect ( x ) . toEqual ( expected . shift ( ) ) ; } ,
358- done . fail ,
359- ( ) => {
360- expect ( expected . length ) . toBe ( 0 ) ;
356+ expect ( x ) . to . deep . equal ( expected . shift ( ) ) ;
357+ } , ( ) => {
358+ done ( new Error ( 'should not be called' ) ) ;
359+ } , ( ) => {
360+ expect ( expected . length ) . to . be . equal ( 0 ) ;
361361 done ( ) ;
362362 } ) ;
363363 } ) ;
364364
365- it ( 'should accept closing selector that returns a rejected promise' , ( done : DoneSignature ) => {
365+ it ( 'should accept closing selector that returns a rejected promise' , ( done : MochaDone ) => {
366366 const e1 = Observable . concat ( Observable . of ( 1 ) ,
367367 Observable . timer ( 10 ) . mapTo ( 2 ) ,
368368 Observable . timer ( 10 ) . mapTo ( 3 ) ,
@@ -373,12 +373,24 @@ describe('Observable.prototype.bufferToggle', () => {
373373
374374 e1 . bufferToggle ( Observable . of ( 10 ) , ( ) => new Promise ( ( resolve : any , reject : any ) => { reject ( expected ) ; } ) )
375375 . subscribe ( ( x ) => {
376- done . fail ( ) ;
376+ done ( new Error ( 'should not be called' ) ) ;
377377 } , ( x ) => {
378- expect ( x ) . toBe ( expected ) ;
378+ expect ( x ) . to . equal ( expected ) ;
379379 done ( ) ;
380380 } , ( ) => {
381- done . fail ( ) ;
381+ done ( new Error ( 'should not be called' ) ) ;
382382 } ) ;
383383 } ) ;
384+
385+ it ( 'should handle empty closing observable' , ( ) => {
386+ const e1 = hot ( '--a--^---b---c---d---e---f---g---h------|' ) ;
387+ const subs = '^ !' ;
388+ const e2 = cold ( '--x-----------y--------z---| ' ) ;
389+ const expected = '--l-----------m--------n-----------|' ;
390+
391+ const result = e1 . bufferToggle ( e2 , ( ) => Observable . empty ( ) ) ;
392+
393+ expectObservable ( result ) . toBe ( expected , { l : [ ] , m : [ ] , n : [ ] } ) ;
394+ expectSubscriptions ( e1 . subscriptions ) . toBe ( subs ) ;
395+ } ) ;
384396} ) ;
0 commit comments