@@ -17,33 +17,33 @@ class MyCommandHandler implements CommandHandler<HandledCommand> {
1717 return HandledCommand ;
1818 }
1919
20- handle ( command : HandledCommand ) : void { }
20+ async handle ( command : HandledCommand ) : Promise < void > { }
2121}
2222
2323describe ( 'InMemoryCommandBus' , ( ) => {
24- it ( 'throws an error if dispatches a command without handler' , done => {
24+ it ( 'throws an error if dispatches a command without handler' , async ( ) => {
2525 const unhandledCommand = new UnhandledCommand ( ) ;
2626 const commandHandlersInformation = new CommandHandlersInformation ( [ ] ) ;
2727 const commandBus = new InMemoryCommandBus ( commandHandlersInformation ) ;
2828
29+ let exception = null ;
30+
2931 try {
30- commandBus . dispatch ( unhandledCommand ) ;
32+ await commandBus . dispatch ( unhandledCommand ) ;
3133 } catch ( error ) {
32- expect ( error ) . toBeInstanceOf ( CommandNotRegisteredError ) ;
33- expect ( error . message ) . toBe ( `The command <UnhandledCommand> hasn't a command handler associated` ) ;
34- done ( ) ;
34+ exception = error ;
3535 }
36+
37+ expect ( exception ) . toBeInstanceOf ( CommandNotRegisteredError ) ;
38+ expect ( exception . message ) . toBe ( `The command <UnhandledCommand> hasn't a command handler associated` ) ;
3639 } ) ;
3740
38- it ( 'accepts a command with handler' , done => {
41+ it ( 'accepts a command with handler' , async ( ) => {
3942 const handledCommand = new HandledCommand ( ) ;
4043 const myCommandHandler = new MyCommandHandler ( ) ;
4144 const commandHandlersInformation = new CommandHandlersInformation ( [ myCommandHandler ] ) ;
4245 const commandBus = new InMemoryCommandBus ( commandHandlersInformation ) ;
4346
44- try {
45- commandBus . dispatch ( handledCommand ) ;
46- done ( ) ;
47- } catch ( error ) { }
47+ await commandBus . dispatch ( handledCommand ) ;
4848 } ) ;
4949} ) ;
0 commit comments