import 'mocha' ; import { expect } from 'chai' ; import { EnumType } from '@/application/Common/Enum' ; export class EnumRangeTestRunner < TEnumValue extends EnumType > { constructor ( private readonly runner ) { } public testOutOfRangeThrows ( ) { it ( 'throws when value is out of range' , ( ) => { const value = Number . MAX_SAFE_INTEGER as TEnumValue ; const expectedError = `enum value "${ value }" is out of range` ; const act = ( ) => this . runner ( value ) ; expect ( act ) . to . throw ( expectedError ) ; } ) ; return this ; } public testUndefinedValueThrows ( ) { it ( 'throws when value is undefined' , ( ) => { const value = undefined ; const expectedError = 'undefined enum value' ; const act = ( ) => this . runner ( value ) ; expect ( act ) . to . throw ( expectedError ) ; } ) ; return this ; } public testInvalidValueThrows ( invalidValue , expectedError ) { it ( `throws ${ expectedError }` , ( ) => { const value = invalidValue ; const act = ( ) => this . runner ( value ) ; expect ( act ) . to . throw ( expectedError ) ; } ) ; return this ; } public testValidValueDoesNotThrow ( validValue ) { it ( 'throws when value is undefined' , ( ) => { const value = validValue ; const act = ( ) => this . runner ( value ) ; expect ( act ) . to . not . throw ( ) ; } ) ; return this ; } }