import * as _ from 'lodash' ; import { Outcome , StateVariables } from '../types' ; export type DeepPartial < T > = { [ P in keyof T ] ? : DeepPartial < T [ P ] > ; } ; type Modifier < T , S extends T = T > = ( result : T , props ? : any ) => S ; /**
 * A fixture accepts two optional, positional arguments
 * - the first, mergeProps, will merge properties into the defaults
 * - the second, extendProps, will overwrite properties of the defaults
 *
 * An example of a property that you wouldn't want to merge is if you want to set a property
 * to `undefined`. In this case, merging the defaults {foo: {bar: 'baz'}} into {foo: undefined}
 * will result in {foo: {bar: 'baz'}}, but extending {foo: undefined} by the defaults
 * {foo: {bar: 'baz'}} will yield {foo: undefined}
 */ export type Fixture < T > = ( mergeProps ? : DeepPartial < T > , extendProps ? : DeepPartial < T > ) => T ; param defaults param modifier export const fixture = function < T > ( defaults , modifier = _ . identity ) : Fixture < T > { return ( mergeProps ? , extendProps ? ) : T => modifier ( _ . extend ( _ . merge ( _ . cloneDeep ( defaults ) , mergeProps ) , extendProps ) , mergeProps ) as T ; } ; export function overwriteOutcome < T extends StateVariables > ( result , props ? ) { if ( props ?. outcome ) result . outcome = props . outcome ; return result ; }