(
options: {
ok?: boolean;
body?: any;
statusText?: string;
status?: number;
headers?: Headers;
text?: () => Promise<string>;
json?: () => Promise<any>;
} = { ok: true },
)
| 39 | } |
| 40 | |
| 41 | export function createMockResponse( |
| 42 | options: { |
| 43 | ok?: boolean; |
| 44 | body?: any; |
| 45 | statusText?: string; |
| 46 | status?: number; |
| 47 | headers?: Headers; |
| 48 | text?: () => Promise<string>; |
| 49 | json?: () => Promise<any>; |
| 50 | } = { ok: true }, |
| 51 | ): Response { |
| 52 | const isOk = options.ok ?? (options.status ? options.status < 400 : true); |
| 53 | const mockResponse: Response = { |
| 54 | ok: isOk, |
| 55 | status: options.status || (isOk ? 200 : 400), |
| 56 | statusText: options.statusText || (isOk ? 'OK' : 'Bad Request'), |
| 57 | headers: options.headers || new Headers(), |
| 58 | redirected: false, |
| 59 | type: 'basic', |
| 60 | url: 'https://example.com', |
| 61 | json: options.json || (() => Promise.resolve(options.body || {})), |
| 62 | text: options.text || (() => Promise.resolve('')), |
| 63 | blob: () => Promise.resolve(new Blob([])), |
| 64 | arrayBuffer: () => Promise.resolve(new ArrayBuffer(0)), |
| 65 | formData: () => Promise.resolve(new FormData()), |
| 66 | bodyUsed: false, |
| 67 | body: null, |
| 68 | clone() { |
| 69 | return createMockResponse(options); |
| 70 | }, |
| 71 | } as Response; |
| 72 | return mockResponse; |
| 73 | } |
| 74 | |
| 75 | export function stripAnsi(value: string): string { |
| 76 | return value.replace(/\u001b\[[0-9;]*m/g, ''); |
searching dependent graphs…