UNPKG

lemon-core

Version:
81 lines (80 loc) 1.96 kB
/** * `common/test-helper.ts` * - helper functions for test * * * @author Steve Jung <steve@lemoncloud.io> * @date 2019-10-16 initial version * * @copyright (C) 2019 LemonCloud Co Ltd. - All Rights Reserved. */ /** * catch error as string * * ```js * const a = sync () => throw new Error('ERROR'); * expect(await a().catch(GETERR)).toEqual('ERROR'); * ``` * @param e */ export declare const GETERR: (e: any) => string; /** * catch error as { error: string } * * ```js * const a = sync () => throw new Error('ERROR'); * expect(await a().catch(GETERR$)).toEqual({ error:'ERROR' }) * ``` * @param e */ export declare const GETERR$: (e: any) => { error: string; }; /** * return null if 404 not found. * @param e error */ export declare const NUL404: (e: Error) => any; /** * improve expect() function with projection field. * * @param test function or data. * @param view projection attributes. */ export declare const expect2: (test: any, view?: string) => any; /** * ignore of `it()` * * @param name * @param callback */ export declare const _it: (name: string, callback?: (done?: any) => any) => void; /** * use `target` as value or environment value. * environ('PROFILE', 'none') => use env.PROFILE if exist, or 'none' */ export declare const environ: (envName: string, envValue?: string) => string; /** * filter function() */ export interface Filter<T> { (name: string, val: any, thiz?: any, attr?: string | number): T; } /** * marshaler: convert object to dotted list. * * @param obj json object * @param name current name * @param list result list * @param filter filter function. */ export declare const marshal: <T>(obj: any, filter: Filter<T>, name?: string, list?: T[], thiz?: any, attr?: string | number) => T[]; /** * wait for some time (in msec). * * ```js * await waited(); * `` * @param t msec */ export declare const waited: (t?: number) => Promise<unknown>;