import { createPromiseFromStreams , createListStream , createIntersperseStream , createConcatStream , } from './index' ; describe ( 'intersperseStream' , ( ) => { test ( 'places the intersperse value between each provided value' , async ( ) => { expect ( await createPromiseFromStreams ( [ createListStream ( [ 'to' , 'be' , 'or' , 'not' , 'to' , 'be' ] ) , createIntersperseStream ( ' ' ) , createConcatStream ( ) , ] ) ) . toBe ( 'to be or not to be' ) ; } ) ; test ( 'emits values as soon as possible, does not needlessly buffer' , async ( ) => { const str = createIntersperseStream ( 'y' ) ; const onData = jest . fn ( ) ; str . on ( 'data' , onData ) ; str . write ( 'a' ) ; expect ( onData ) . toHaveBeenCalledTimes ( 1 ) ; expect ( onData . mock . calls [ 0 ] ) . toEqual ( [ 'a' ] ) ; onData . mockClear ( ) ; str . write ( 'b' ) ; expect ( onData ) . toHaveBeenCalledTimes ( 2 ) ; expect ( onData . mock . calls [ 0 ] ) . toEqual ( [ 'y' ] ) ; expect ( onData ) . toHaveBeenCalledTimes ( 2 ) ; expect ( onData . mock . calls [ 1 ] ) . toEqual ( [ 'b' ] ) ; } ) ; } ) ;