import { expect } from 'chai' ; import { GenericErrorMapper } from '../../../../lib/dispatcher/error/mapper/GenericErrorMapper' ; import { MockAlwaysFalseErrorHandler } from '../../../mocks/error/MockAlwaysFalseErrorHandler' ; import { MockAlwaysTrueErrorHandler } from '../../../mocks/error/MockAlwaysTrueErrorHandler' ; describe ( 'GenericErrorMapper' , ( ) => { it ( 'should be able to get the error handler that can handle the error' , async ( ) => { const mapper = new GenericErrorMapper < string , string > ( { errorHandlers : [ new MockAlwaysTrueErrorHandler ( ) , new MockAlwaysFalseErrorHandler ( ) , ] , } ) ; const handler = await mapper . getErrorHandler ( null , new Error ( 'Test error' ) ) ; expect ( handler ) . instanceof ( MockAlwaysTrueErrorHandler ) ; } ) ; it ( 'should return null if no error handle can handle the error' , async ( ) => { const mapper = new GenericErrorMapper < string , string > ( { errorHandlers : [ new MockAlwaysFalseErrorHandler ( ) , ] , } ) ; const handler = await mapper . getErrorHandler ( null , new Error ( 'Test error' ) ) ; expect ( handler ) . equal ( null ) ; } ) ; } ) ;