| 23 | |
| 24 | /** Creates a mock of `Application`. */ |
| 25 | export function createMockApp< |
| 26 | S extends Record<PropertyKey, any> = Record<string, any>, |
| 27 | >( |
| 28 | state: S = {} as S, |
| 29 | ): Application<S> { |
| 30 | const app = { |
| 31 | state, |
| 32 | use() { |
| 33 | return app; |
| 34 | }, |
| 35 | [Symbol.for("Deno.customInspect")]() { |
| 36 | return "MockApplication {}"; |
| 37 | }, |
| 38 | [Symbol.for("nodejs.util.inspect.custom")]( |
| 39 | depth: number, |
| 40 | options: any, |
| 41 | inspect: (value: unknown, options?: unknown) => string, |
| 42 | ) { |
| 43 | if (depth < 0) { |
| 44 | return options.stylize(`[MockApplication]`, "special"); |
| 45 | } |
| 46 | |
| 47 | const newOptions = Object.assign({}, options, { |
| 48 | depth: options.depth === null ? null : options.depth - 1, |
| 49 | }); |
| 50 | return `${options.stylize("MockApplication", "special")} ${ |
| 51 | inspect({}, newOptions) |
| 52 | }`; |
| 53 | }, |
| 54 | } as any; |
| 55 | return app; |
| 56 | } |
| 57 | |
| 58 | /** Options that can be set in a mock context. */ |
| 59 | export interface MockContextOptions< |