diff --git a/src/index.ts b/src/index.ts index 33c992e..9a96463 100644 --- a/src/index.ts +++ b/src/index.ts @@ -72,11 +72,20 @@ class HttpBackend { // very simplistic mapping from the whatwg fetch interface onto the request // interface, so we can use the same mock backend for both. - public fetchFn = (input: string, init?: Omit): Promise<{ ok: boolean, json: () => unknown }> => { + public fetchFn = (input: URL | string, init?: Omit): Promise<{ + ok: boolean; + status: number; + json: () => unknown; + }> => { + const url = new URL(input); + const qs = Object.fromEntries(url.searchParams); + const requestOpts = { - uri: input, + uri: url.href, method: init?.method || 'GET', + headers: init?.headers, body: init?.body, + qs, }; return new Promise((resolve, reject) => { @@ -86,6 +95,7 @@ class HttpBackend { } resolve({ ok: response.statusCode >= 200 && response.statusCode < 300, + status: response.statusCode, json: () => JSON.parse(body), }); };