import { CancellationToken } from './cancellation_token' ; describe ( 'Cancellation Token' , ( ) => { it ( 'registers callbacks for cancellation events' , ( ) => { const cancellationToken = new CancellationToken ( ) ; const onCancelled = jest . fn ( ) ; cancellationToken . on ( onCancelled ) ; cancellationToken . cancel ( ) ; expect ( onCancelled ) . toBeCalled ( ) ; } ) ; it ( 'emits a cancellation event immediately when already cancelled' , ( ) => { const cancellationToken = new CancellationToken ( ) ; const onCancelled = jest . fn ( ) ; cancellationToken . cancel ( ) ; cancellationToken . on ( onCancelled ) ; expect ( onCancelled ) . toBeCalled ( ) ; } ) ; it ( 'binds the `on` method properly so that it can be passed around' , ( ) => { const cancellationToken = new CancellationToken ( ) ; const onCancelled = jest . fn ( ) ; const unboundOn = cancellationToken . on ; cancellationToken . cancel ( ) ; unboundOn ( onCancelled ) ; expect ( onCancelled ) . toBeCalled ( ) ; } ) ; it ( 'binds the `cancel` method properly so that it can be passed around' , ( ) => { const cancellationToken = new CancellationToken ( ) ; const onCancelled = jest . fn ( ) ; const unboundCancel = cancellationToken . cancel ; unboundCancel ( ) ; cancellationToken . on ( onCancelled ) ; expect ( onCancelled ) . toBeCalled ( ) ; } ) ; } ) ;