(context: Record<T, any>)
| 36 | context?: Record<string, any>, |
| 37 | ): ChainableFunction<T, (...args: Args) => R> { |
| 38 | function create(context: Record<T, any>) { |
| 39 | const chain = function (this: any, ...args: Args) { |
| 40 | return fn.apply(context, args) |
| 41 | } |
| 42 | Object.assign(chain, fn) |
| 43 | Object.defineProperty(chain, kChainableContext, { |
| 44 | value: { |
| 45 | withContext: () => chain.bind(context), |
| 46 | getFixtures: () => (context as any).fixtures, |
| 47 | setContext: (key: T, value: any) => { |
| 48 | context[key] = value |
| 49 | }, |
| 50 | mergeContext: (ctx: Record<T, any>) => { |
| 51 | Object.assign(context, ctx) |
| 52 | }, |
| 53 | }, |
| 54 | enumerable: false, |
| 55 | }) |
| 56 | for (const key of keys) { |
| 57 | Object.defineProperty(chain, key, { |
| 58 | get() { |
| 59 | return create({ ...context, [key]: true }) |
| 60 | }, |
| 61 | }) |
| 62 | } |
| 63 | return chain |
| 64 | } |
| 65 | |
| 66 | const chain = create(context ?? {} as any) as any |
| 67 | Object.defineProperty(chain, 'fn', { |
no test coverage detected