import chai from 'chai' ; export function objValues ( obj , mapFunc ) { return Object . keys ( obj ) . filter ( key => key . match ( /^[\d_]/ ) == null ) . reduce ( ( set , key ) => ( { ... set , [ key ] : mapFunc ( obj [ key ] , key ) } ) , { } ) ; } /**
 * cleanup a value of an object, for easier testing.
 * - Result: this is an array which also contains named members.
 *      - obj.length*2 == Object.keys().length
 *      - remove the array elements, use just the named ones.
 * - recursively handle inner members of object, arrays.
 * - attempt toString. but if no normal value, recurse into fields.
 */ export function cleanValue ( val ) { if ( val == null ) return val ; if ( Array . isArray ( val ) ) { if ( val . length * 2 === Object . keys ( val ) . length ) { return objValues ( val , cleanValue ) ; } return val . map ( val1 => cleanValue ( val1 ) ) ; } const str = val . toString ( ) ; if ( str !== '[object Object]' ) { return str ; } return objValues ( val , cleanValue ) ; } chai . Assertion . overwriteMethod ( 'eql' , ( original ) => { return function ( this , expected ) { const _actual = cleanValue ( this . _obj ) ; const _expected = cleanValue ( expected ) ; this . _obj = _actual ; original . apply ( this , [ _expected ] ) ; } ; } ) ;