import { expect } from 'chai' ; import { describe , it } from 'mocha' ; import { SimplePubSub } from './simplePubSub' ; describe ( 'SimplePubSub' , ( ) => { it ( 'subscribe async-iterator mock' , async ( ) => { const pubsub = new SimplePubSub ( ) ; const iterator = pubsub . getSubscriber ( ( x ) => x ) ; expect ( pubsub . emit ( 'Apple' ) ) . to . equal ( true ) ; expect ( pubsub . emit ( 'Banana' ) ) . to . equal ( true ) ; expect ( await iterator . next ( ) ) . to . deep . equal ( { done : false , value : 'Apple' , } ) ; expect ( await iterator . next ( ) ) . to . deep . equal ( { done : false , value : 'Banana' , } ) ; const i3 = iterator . next ( ) . then ( ( x ) => x ) ; const i4 = iterator . next ( ) . then ( ( x ) => x ) ; expect ( pubsub . emit ( 'Coconut' ) ) . to . equal ( true ) ; expect ( pubsub . emit ( 'Durian' ) ) . to . equal ( true ) ; expect ( await i4 ) . to . deep . equal ( { done : false , value : 'Durian' } ) ; expect ( await i3 ) . to . deep . equal ( { done : false , value : 'Coconut' } ) ; const i5 = iterator . next ( ) . then ( ( x ) => x ) ; await iterator . return ( ) ; expect ( pubsub . emit ( 'Fig' ) ) . to . equal ( false ) ; expect ( await i5 ) . to . deep . equal ( { done : true , value : undefined } ) ; expect ( await iterator . next ( ) ) . to . deep . equal ( { done : true , value : undefined , } ) ; } ) ; } ) ;