import * as Units from ".." ; import { Measure } from "../../measure/numberMeasure" ; describe ( "Predefined units" , ( ) => { const UnitNames = Object . keys ( Units ) ; const lowercaseFirstRegex = /^[a-z]/ ; function forEachUnit ( fn ) { const wrappedCallback = ( value , name ) => { if ( Measure . isMeasure ( value ) && lowercaseFirstRegex . test ( name ) ) { fn ( value , name ) ; } } ; UnitNames . forEach ( name => { const value = ( Units as any ) [ name ] ; if ( Measure . isMeasure ( value ) ) { wrappedCallback ( value , name ) ; } else { for ( const subName in value ) { if ( value . hasOwnProperty ( subName ) ) { const unit = value [ subName ] ; wrappedCallback ( unit , subName ) ; } } } } ) ; } it ( "all units should have a symbol" , ( ) => { forEachUnit ( ( unit , name ) => { try { expect ( unit . symbol ) . not . toBeUndefined ( ) ; } catch ( e ) { console . log ( `Unit ${ name } has no symbol defined.` ) ; throw e ; } } ) ; } ) ; } ) ;