import { scheduled , of } from 'rxjs' ; import { TestScheduler } from 'rxjs/testing' ; import { lowerCaseO } from '../helpers/test-helper' ; import { observableMatcher } from '../helpers/observableMatcher' ; import { expect } from 'chai' ; describe ( 'scheduled' , ( ) => { let testScheduler ; beforeEach ( ( ) => { testScheduler = new TestScheduler ( observableMatcher ) ; } ) ; it ( 'should schedule a sync observable' , ( ) => { const input = of ( 'a' , 'b' , 'c' ) ; testScheduler . run ( ( { expectObservable } ) => { expectObservable ( scheduled ( input , testScheduler ) ) . toBe ( '(abc|)' ) ; } ) ; } ) ; it ( 'should schedule an array' , ( ) => { const input = [ 'a' , 'b' , 'c' ] ; testScheduler . run ( ( { expectObservable } ) => { expectObservable ( scheduled ( input , testScheduler ) ) . toBe ( '(abc|)' ) ; } ) ; } ) ; it ( 'should schedule an iterable' , ( ) => { const input = 'abc' ; testScheduler . run ( ( { expectObservable } ) => { expectObservable ( scheduled ( input , testScheduler ) ) . toBe ( '(abc|)' ) ; } ) ; } ) ; it ( 'should schedule an observable-like' , ( ) => { const input = lowerCaseO ( 'a' , 'b' , 'c' ) ; testScheduler . run ( ( { expectObservable } ) => { expectObservable ( scheduled ( input , testScheduler ) ) . toBe ( '(abc|)' ) ; } ) ; } ) ; it ( 'should schedule a promise' , ( done ) => { const results = [ ] ; const input = Promise . resolve ( 'x' ) ; scheduled ( input , testScheduler ) . subscribe ( { next ( value ) { results . push ( value ) ; } , complete ( ) { results . push ( 'done' ) ; } , } ) ; expect ( results ) . to . deep . equal ( [ ] ) ; testScheduler . flush ( ) ; expect ( results ) . to . deep . equal ( [ ] ) ; Promise . resolve ( ) . then ( ( ) => { testScheduler . flush ( ) ; expect ( results ) . to . deep . equal ( [ 'x' , 'done' ] ) ; done ( ) ; } ) ; } ) ; } ) ;