From f79718378bc7e6fb82261dc93a13fe778df3adee Mon Sep 17 00:00:00 2001 From: Alex Olson Date: Sat, 27 Nov 2021 02:33:33 +0100 Subject: [PATCH 1/8] support buffers when mocking responses (#218) --- tests/test.js | 11 +++++++++++ types/index.d.ts | 4 ++-- types/test.ts | 45 ++++++++++++++++++++++++++------------------- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/tests/test.js b/tests/test.js index 5f0cea0..cd9e972 100644 --- a/tests/test.js +++ b/tests/test.js @@ -1,5 +1,7 @@ +const { StringDecoder } = require('string_decoder'); const { APIRequest, APIRequest2, defaultRequestUri, request } = require('./api') + describe('testing mockResponse and alias once', () => { beforeEach(() => { fetch.resetMocks() @@ -358,6 +360,15 @@ describe('request', () => { fetch('https://bar', {}).then((response) => response.headers.get('ding')) ).resolves.toEqual('dang') }) + + it('resolves with mocked response containing buffer', () => { + fetch.mockResponseOnce(() => Promise.resolve(new Response(Buffer.from('foo')))) + return expect( + fetch('https://bar', {}) + .then((response) => response.arrayBuffer()) + .then((arrayBuffer) => new StringDecoder('utf8').write(new Uint8Array(arrayBuffer))) + ).resolves.toEqual('foo') + }); }) describe('conditional mocking', () => { diff --git a/types/index.d.ts b/types/index.d.ts index 22ae47b..df81c5b 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -91,14 +91,14 @@ export interface MockParams { } export interface MockResponseInit extends MockParams { - body?: string; + body?: string | Buffer; init?: MockParams; } export type ErrorOrFunction = Error | ((...args: any[]) => Promise); export type UrlOrPredicate = string | RegExp | ((input: Request) => boolean); -export type MockResponseInitFunction = (request: Request) => MockResponseInit | string | Promise; +export type MockResponseInitFunction = (request: Request) => MockResponseInit | string | Promise; // alias of fetchMock.enableMocks() for ES6 import syntax to not clash with other libraries export function enableFetchMocks(): void; diff --git a/types/test.ts b/types/test.ts index f401788..9ffc97a 100644 --- a/types/test.ts +++ b/types/test.ts @@ -1,49 +1,52 @@ import fm, { enableFetchMocks, disableFetchMocks, MockResponseInit } from 'jest-fetch-mock'; -fetchMock.mockResponse(JSON.stringify({foo: "bar"})); -fetchMock.mockResponse(JSON.stringify({foo: "bar"}), { +fetchMock.mockResponse(JSON.stringify({ foo: "bar" })); +fetchMock.mockResponse(JSON.stringify({ foo: "bar" }), { status: 200, headers: [ ["Content-Type", "application/json"] ] }); -fetchMock.mockResponse(JSON.stringify({foo: "bar"}), {}); +fetchMock.mockResponse(JSON.stringify({ foo: "bar" }), {}); fetchMock.mockResponse(someAsyncHandler); fetchMock.mockResponse(someAsyncStringHandler); +fetchMock.mockResponse(someAsyncBufferHandler) -fetchMock.mockResponseOnce(JSON.stringify({foo: "bar"})); -fetchMock.mockResponseOnce(JSON.stringify({foo: "bar"}), { +fetchMock.mockResponseOnce(JSON.stringify({ foo: "bar" })); +fetchMock.mockResponseOnce(JSON.stringify({ foo: "bar" }), { status: 200, headers: [ ["Content-Type", "application/json"] ] }); -fetchMock.mockResponseOnce(JSON.stringify({foo: "bar"}), {}); +fetchMock.mockResponseOnce(JSON.stringify({ foo: "bar" }), {}); fetchMock.mockResponseOnce(someAsyncHandler); fetchMock.mockResponseOnce(someAsyncStringHandler); +fetchMock.mockResponseOnce(someAsyncBufferHandler) -fetchMock.once(JSON.stringify({foo: "bar"})); -fetchMock.once(JSON.stringify({foo: "bar"}), { +fetchMock.once(JSON.stringify({ foo: "bar" })); +fetchMock.once(JSON.stringify({ foo: "bar" }), { status: 200, headers: [ ["Content-Type", "application/json"] ] }); -fetchMock.once(JSON.stringify({foo: "bar"}), {}); +fetchMock.once(JSON.stringify({ foo: "bar" }), {}); fetchMock.once(someAsyncHandler); -fetchMock.mockResponses(JSON.stringify({}), JSON.stringify({foo: "bar"})); +fetchMock.mockResponses(JSON.stringify({}), JSON.stringify({ foo: "bar" })); fetchMock.mockResponses(someAsyncHandler, someAsyncHandler); fetchMock.mockResponses(JSON.stringify({}), someAsyncHandler); fetchMock.mockResponses(someAsyncHandler, JSON.stringify({})); fetchMock.mockResponses(someAsyncHandler); -fetchMock.mockResponses([JSON.stringify({foo: "bar"}), {status: 200}]); +fetchMock.mockResponses([JSON.stringify({ foo: "bar" }), { status: 200 }]); fetchMock.mockResponses( someSyncHandler, someAsyncHandler, someSyncStringHandler, someAsyncStringHandler, - [JSON.stringify({foo: "bar"}), {status: 200}] + someAsyncBufferHandler, + [JSON.stringify({ foo: "bar" }), { status: 200 }] ); fetchMock.mockReject(new Error("oops")); @@ -60,22 +63,22 @@ fetchMock.isMocking(new Request("http://bang")); fetchMock.doMockIf('http://foo'); fetchMock.doMockIf(/bar/); -fetchMock.doMockIf((input: Request|string) => true); +fetchMock.doMockIf((input: Request | string) => true); fetchMock.mockIf('http://foo'); fetchMock.mockIf(/bar/); -fetchMock.mockIf((input: Request|string) => true); +fetchMock.mockIf((input: Request | string) => true); fetchMock.dontMockIf('http://foo'); fetchMock.dontMockIf(/bar/); -fetchMock.dontMockIf((input: Request|string) => true); +fetchMock.dontMockIf((input: Request | string) => true); fetchMock.doMockOnceIf('http://foo'); fetchMock.doMockOnceIf(/bar/); -fetchMock.doMockOnceIf((input: Request|string) => true); +fetchMock.doMockOnceIf((input: Request | string) => true); fetchMock.mockOnceIf('http://foo'); fetchMock.mockOnceIf(/bar/); -fetchMock.mockOnceIf((input: Request|string) => true); +fetchMock.mockOnceIf((input: Request | string) => true); fetchMock.dontMockOnceIf('http://foo'); fetchMock.dontMockOnceIf(/bar/); -fetchMock.dontMockOnceIf((input: Request|string) => true); +fetchMock.dontMockOnceIf((input: Request | string) => true); fetchMock.doMock(); fetchMock.dontMock(); @@ -102,7 +105,11 @@ async function someAsyncStringHandler(): Promise { } function someSyncStringHandler(): string { - return JSON.stringify({foo: "bar"}); + return JSON.stringify({ foo: "bar" }); +} + +async function someAsyncBufferHandler(): Promise { + return new Response(Buffer.from('foo')); } enableFetchMocks(); From bc362ba978f8af0a97811cab77952eb55f3d2541 Mon Sep 17 00:00:00 2001 From: Alex Olson Date: Sat, 27 Nov 2021 02:36:44 +0100 Subject: [PATCH 2/8] remove buffer as body option for now --- types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index df81c5b..47810bf 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -91,7 +91,7 @@ export interface MockParams { } export interface MockResponseInit extends MockParams { - body?: string | Buffer; + body?: string; init?: MockParams; } From c5e0423a1566a9d5b14a06a964a2f896c73c96af Mon Sep 17 00:00:00 2001 From: Alex Olson Date: Sat, 27 Nov 2021 02:46:44 +0100 Subject: [PATCH 3/8] remove vscode auto-formatting of my changes --- types/test.ts | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/types/test.ts b/types/test.ts index 9ffc97a..5fc16ae 100644 --- a/types/test.ts +++ b/types/test.ts @@ -1,52 +1,52 @@ import fm, { enableFetchMocks, disableFetchMocks, MockResponseInit } from 'jest-fetch-mock'; -fetchMock.mockResponse(JSON.stringify({ foo: "bar" })); -fetchMock.mockResponse(JSON.stringify({ foo: "bar" }), { +fetchMock.mockResponse(JSON.stringify({foo: "bar"})); +fetchMock.mockResponse(JSON.stringify({foo: "bar"}), { status: 200, headers: [ ["Content-Type", "application/json"] ] }); -fetchMock.mockResponse(JSON.stringify({ foo: "bar" }), {}); +fetchMock.mockResponse(JSON.stringify({foo: "bar"}), {}); fetchMock.mockResponse(someAsyncHandler); fetchMock.mockResponse(someAsyncStringHandler); fetchMock.mockResponse(someAsyncBufferHandler) -fetchMock.mockResponseOnce(JSON.stringify({ foo: "bar" })); -fetchMock.mockResponseOnce(JSON.stringify({ foo: "bar" }), { +fetchMock.mockResponseOnce(JSON.stringify({foo: "bar"})); +fetchMock.mockResponseOnce(JSON.stringify({foo: "bar"}), { status: 200, headers: [ ["Content-Type", "application/json"] ] }); -fetchMock.mockResponseOnce(JSON.stringify({ foo: "bar" }), {}); +fetchMock.mockResponseOnce(JSON.stringify({foo: "bar"}), {}); fetchMock.mockResponseOnce(someAsyncHandler); fetchMock.mockResponseOnce(someAsyncStringHandler); fetchMock.mockResponseOnce(someAsyncBufferHandler) -fetchMock.once(JSON.stringify({ foo: "bar" })); -fetchMock.once(JSON.stringify({ foo: "bar" }), { +fetchMock.once(JSON.stringify({foo: "bar"})); +fetchMock.once(JSON.stringify({foo: "bar"}), { status: 200, headers: [ ["Content-Type", "application/json"] ] }); -fetchMock.once(JSON.stringify({ foo: "bar" }), {}); +fetchMock.once(JSON.stringify({foo: "bar"}), {}); fetchMock.once(someAsyncHandler); -fetchMock.mockResponses(JSON.stringify({}), JSON.stringify({ foo: "bar" })); +fetchMock.mockResponses(JSON.stringify({}), JSON.stringify({foo: "bar"})); fetchMock.mockResponses(someAsyncHandler, someAsyncHandler); fetchMock.mockResponses(JSON.stringify({}), someAsyncHandler); fetchMock.mockResponses(someAsyncHandler, JSON.stringify({})); fetchMock.mockResponses(someAsyncHandler); -fetchMock.mockResponses([JSON.stringify({ foo: "bar" }), { status: 200 }]); +fetchMock.mockResponses([JSON.stringify({foo: "bar"}), {status: 200}]); fetchMock.mockResponses( someSyncHandler, someAsyncHandler, someSyncStringHandler, someAsyncStringHandler, someAsyncBufferHandler, - [JSON.stringify({ foo: "bar" }), { status: 200 }] + [JSON.stringify({foo: "bar"}), {status: 200}] ); fetchMock.mockReject(new Error("oops")); @@ -63,22 +63,22 @@ fetchMock.isMocking(new Request("http://bang")); fetchMock.doMockIf('http://foo'); fetchMock.doMockIf(/bar/); -fetchMock.doMockIf((input: Request | string) => true); +fetchMock.doMockIf((input: Request|string) => true); fetchMock.mockIf('http://foo'); fetchMock.mockIf(/bar/); -fetchMock.mockIf((input: Request | string) => true); +fetchMock.mockIf((input: Request|string) => true); fetchMock.dontMockIf('http://foo'); fetchMock.dontMockIf(/bar/); -fetchMock.dontMockIf((input: Request | string) => true); +fetchMock.dontMockIf((input: Request|string) => true); fetchMock.doMockOnceIf('http://foo'); fetchMock.doMockOnceIf(/bar/); -fetchMock.doMockOnceIf((input: Request | string) => true); +fetchMock.doMockOnceIf((input: Request|string) => true); fetchMock.mockOnceIf('http://foo'); fetchMock.mockOnceIf(/bar/); -fetchMock.mockOnceIf((input: Request | string) => true); +fetchMock.mockOnceIf((input: Request|string) => true); fetchMock.dontMockOnceIf('http://foo'); fetchMock.dontMockOnceIf(/bar/); -fetchMock.dontMockOnceIf((input: Request | string) => true); +fetchMock.dontMockOnceIf((input: Request|string) => true); fetchMock.doMock(); fetchMock.dontMock(); @@ -105,7 +105,7 @@ async function someAsyncStringHandler(): Promise { } function someSyncStringHandler(): string { - return JSON.stringify({ foo: "bar" }); + return JSON.stringify({foo: "bar"}); } async function someAsyncBufferHandler(): Promise { From fee6693bf5f9c0a698ce9d17dd1d7537f5585b85 Mon Sep 17 00:00:00 2001 From: Alex Olson Date: Sat, 27 Nov 2021 02:50:33 +0100 Subject: [PATCH 4/8] remove erroneously added newline --- tests/test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test.js b/tests/test.js index cd9e972..87b5a49 100644 --- a/tests/test.js +++ b/tests/test.js @@ -1,7 +1,6 @@ const { StringDecoder } = require('string_decoder'); const { APIRequest, APIRequest2, defaultRequestUri, request } = require('./api') - describe('testing mockResponse and alias once', () => { beforeEach(() => { fetch.resetMocks() From 75bfa2c4d518bc083eb4e92f46445f16a472bca1 Mon Sep 17 00:00:00 2001 From: Alex Olson Date: Sat, 27 Nov 2021 14:12:40 +0100 Subject: [PATCH 5/8] make symmetric thanks @andreasg123! Co-authored-by: Andreas Girgensohn --- types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/index.d.ts b/types/index.d.ts index 47810bf..f0bc9a6 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -98,7 +98,7 @@ export interface MockResponseInit extends MockParams { export type ErrorOrFunction = Error | ((...args: any[]) => Promise); export type UrlOrPredicate = string | RegExp | ((input: Request) => boolean); -export type MockResponseInitFunction = (request: Request) => MockResponseInit | string | Promise; +export type MockResponseInitFunction = (request: Request) => MockResponseInit | string | Response | Promise; // alias of fetchMock.enableMocks() for ES6 import syntax to not clash with other libraries export function enableFetchMocks(): void; From 515a820cda411d62038d08d8e14b0fd8a98a6ec1 Mon Sep 17 00:00:00 2001 From: Alex Olson Date: Sun, 28 Nov 2021 18:30:17 +0100 Subject: [PATCH 6/8] add support for mocking with already instantiated Response objects --- README.md | 4 +++- src/index.js | 4 ++++ tests/test.js | 13 +++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 956924f..f945afd 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,7 @@ If you are using [Create-React-App](https://github.com/facebookincubator/create- ### Functions Instead of passing body, it is also possible to pass a function that returns a promise. -The promise should resolve with a string or an object containing body and init props +The promise should resolve with a string or an object containing body and init props, or a `Response` object. i.e: @@ -186,6 +186,8 @@ i.e: fetch.mockResponse(() => callMyApi().then(res => ({ body: 'ok' }))) // OR fetch.mockResponse(() => callMyApi().then(res => 'ok')) +// OR +fetch.mockResponse(() => callMyApi().then(res => new Response('foo'))) ``` The function may take an optional "request" parameter of type `http.Request`: diff --git a/src/index.js b/src/index.js index 4ac478d..a40570c 100644 --- a/src/index.js +++ b/src/index.js @@ -17,6 +17,10 @@ if (typeof DOMException === 'undefined') { const ActualResponse = Response function responseWrapper(body, init) { + if (body instanceof ActualResponse) { + return body; + } + if ( body && typeof body.constructor === 'function' && diff --git a/tests/test.js b/tests/test.js index 87b5a49..a61d8c4 100644 --- a/tests/test.js +++ b/tests/test.js @@ -360,14 +360,23 @@ describe('request', () => { ).resolves.toEqual('dang') }) - it('resolves with mocked response containing buffer', () => { + it('accepts a promise containing a repsonse containing a buffer', () => { fetch.mockResponseOnce(() => Promise.resolve(new Response(Buffer.from('foo')))) return expect( fetch('https://bar', {}) .then((response) => response.arrayBuffer()) .then((arrayBuffer) => new StringDecoder('utf8').write(new Uint8Array(arrayBuffer))) ).resolves.toEqual('foo') - }); + }) + + it('accepts a response containing a buffer', () => { + fetch.mockResponseOnce(new Response(Buffer.from('foo'))) + return expect( + fetch('https://bar', {}) + .then((response) => response.arrayBuffer()) + .then((arrayBuffer) => new StringDecoder('utf8').write(new Uint8Array(arrayBuffer))) + ).resolves.toEqual('foo') + }) }) describe('conditional mocking', () => { From 484ff938a9b64891cec2bb80c0c4e6fbb2440755 Mon Sep 17 00:00:00 2001 From: Alex Olson Date: Sun, 28 Nov 2021 18:48:00 +0100 Subject: [PATCH 7/8] add missing typescript function signatures --- types/index.d.ts | 16 +++++++++++++++- types/test.ts | 14 ++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index f0bc9a6..174330b 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -23,15 +23,18 @@ export interface FetchMock // Response mocking mockResponse(fn: MockResponseInitFunction): FetchMock; mockResponse(response: string, responseInit?: MockParams): FetchMock; + mockResponse(response: Response): FetchMock; mockResponseOnce(fn: MockResponseInitFunction): FetchMock; mockResponseOnce(response: string, responseInit?: MockParams): FetchMock; + mockResponseOnce(response: Response): FetchMock; // alias for mockResponseOnce once(fn: MockResponseInitFunction): FetchMock; + once(response: Response): FetchMock; once(url: string, responseInit?: MockParams): FetchMock; - mockResponses(...responses: Array): FetchMock; + mockResponses(...responses: Array): FetchMock; // Error/Reject mocking mockReject(error?: ErrorOrFunction): FetchMock; @@ -45,36 +48,47 @@ export interface FetchMock doMock(fn?: MockResponseInitFunction): FetchMock; doMock(response: string, responseInit?: MockParams): FetchMock; + doMock(response: Response): FetchMock; doMockOnce(fn?: MockResponseInitFunction): FetchMock; doMockOnce(response: string, responseInit?: MockParams): FetchMock; + doMockOnce(response: Response): FetchMock; // alias for doMockOnce mockOnce(fn?: MockResponseInitFunction): FetchMock; mockOnce(response: string, responseInit?: MockParams): FetchMock; + mockOnce(response: Response): FetchMock; doMockIf(urlOrPredicate: UrlOrPredicate, fn?: MockResponseInitFunction): FetchMock; doMockIf(urlOrPredicate: UrlOrPredicate, response: string, responseInit?: MockParams): FetchMock; + doMockIf(urlOrPredicate: UrlOrPredicate, response: Response) : FetchMock; // alias for doMockIf mockIf(urlOrPredicate: UrlOrPredicate, fn?: MockResponseInitFunction): FetchMock; mockIf(urlOrPredicate: UrlOrPredicate, response: string, responseInit?: MockParams): FetchMock; + mockIf(urlOrPredicate: UrlOrPredicate, response: Response) : FetchMock; doMockOnceIf(urlOrPredicate: UrlOrPredicate, fn?: MockResponseInitFunction): FetchMock; doMockOnceIf(urlOrPredicate: UrlOrPredicate, response: string, responseInit?: MockParams): FetchMock; + doMockOnceIf(urlOrPredicate: UrlOrPredicate, response: Response) : FetchMock; // alias for doMocKOnceIf mockOnceIf(urlOrPredicate: UrlOrPredicate, fn?: MockResponseInitFunction): FetchMock; mockOnceIf(urlOrPredicate: UrlOrPredicate, response: string, responseInit?: MockParams): FetchMock; + mockOnceIf(urlOrPredicate: UrlOrPredicate, response: Response) : FetchMock; dontMock(fn?: MockResponseInitFunction): FetchMock; dontMock(response: string, responseInit?: MockParams): FetchMock; + dontMock(response: Response): FetchMock; dontMockOnce(fn?: MockResponseInitFunction): FetchMock; dontMockOnce(response: string, responseInit?: MockParams): FetchMock; + dontMockOnce(response: Response): FetchMock; dontMockIf(urlOrPredicate: UrlOrPredicate, fn?: MockResponseInitFunction): FetchMock; dontMockIf(urlOrPredicate: UrlOrPredicate, response: string, responseInit?: MockParams): FetchMock; + dontMockIf(urlOrPredicate: UrlOrPredicate, response: Response): FetchMock; dontMockOnceIf(urlOrPredicate: UrlOrPredicate, fn?: MockResponseInitFunction): FetchMock; dontMockOnceIf(urlOrPredicate: UrlOrPredicate, response: string, responseInit?: MockParams): FetchMock; + dontMockOnceIf(urlOrPredicate: UrlOrPredicate, response: Response): FetchMock; resetMocks(): void; enableMocks(): void; diff --git a/types/test.ts b/types/test.ts index 5fc16ae..ef0e67d 100644 --- a/types/test.ts +++ b/types/test.ts @@ -8,9 +8,10 @@ fetchMock.mockResponse(JSON.stringify({foo: "bar"}), { ] }); fetchMock.mockResponse(JSON.stringify({foo: "bar"}), {}); +fetchMock.mockResponse(new Response('foo')); fetchMock.mockResponse(someAsyncHandler); fetchMock.mockResponse(someAsyncStringHandler); -fetchMock.mockResponse(someAsyncBufferHandler) +fetchMock.mockResponse(someAsyncResponseHandler) fetchMock.mockResponseOnce(JSON.stringify({foo: "bar"})); fetchMock.mockResponseOnce(JSON.stringify({foo: "bar"}), { @@ -20,9 +21,10 @@ fetchMock.mockResponseOnce(JSON.stringify({foo: "bar"}), { ] }); fetchMock.mockResponseOnce(JSON.stringify({foo: "bar"}), {}); +fetchMock.mockResponseOnce(new Response('foo')); fetchMock.mockResponseOnce(someAsyncHandler); fetchMock.mockResponseOnce(someAsyncStringHandler); -fetchMock.mockResponseOnce(someAsyncBufferHandler) +fetchMock.mockResponseOnce(someAsyncResponseHandler) fetchMock.once(JSON.stringify({foo: "bar"})); fetchMock.once(JSON.stringify({foo: "bar"}), { @@ -32,7 +34,9 @@ fetchMock.once(JSON.stringify({foo: "bar"}), { ] }); fetchMock.once(JSON.stringify({foo: "bar"}), {}); +fetchMock.once(new Response('foo')); fetchMock.once(someAsyncHandler); +fetchMock.once(someAsyncResponseHandler); fetchMock.mockResponses(JSON.stringify({}), JSON.stringify({foo: "bar"})); fetchMock.mockResponses(someAsyncHandler, someAsyncHandler); @@ -40,12 +44,14 @@ fetchMock.mockResponses(JSON.stringify({}), someAsyncHandler); fetchMock.mockResponses(someAsyncHandler, JSON.stringify({})); fetchMock.mockResponses(someAsyncHandler); fetchMock.mockResponses([JSON.stringify({foo: "bar"}), {status: 200}]); +fetchMock.mockResponses(new Response('foo')) +fetchMock.mockResponses(JSON.stringify({}), new Response('foo')) fetchMock.mockResponses( someSyncHandler, someAsyncHandler, someSyncStringHandler, someAsyncStringHandler, - someAsyncBufferHandler, + someAsyncResponseHandler, [JSON.stringify({foo: "bar"}), {status: 200}] ); @@ -108,7 +114,7 @@ function someSyncStringHandler(): string { return JSON.stringify({foo: "bar"}); } -async function someAsyncBufferHandler(): Promise { +async function someAsyncResponseHandler(): Promise { return new Response(Buffer.from('foo')); } From 806eb414e4210e20fc12fb201c6c348c5abacfca Mon Sep 17 00:00:00 2001 From: Alex Olson Date: Sun, 28 Nov 2021 20:08:43 +0100 Subject: [PATCH 8/8] adjust wording, the buffer part is not relevant. --- tests/test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test.js b/tests/test.js index a61d8c4..534badd 100644 --- a/tests/test.js +++ b/tests/test.js @@ -360,7 +360,7 @@ describe('request', () => { ).resolves.toEqual('dang') }) - it('accepts a promise containing a repsonse containing a buffer', () => { + it('accepts a promise that resolves with a repsonse', () => { fetch.mockResponseOnce(() => Promise.resolve(new Response(Buffer.from('foo')))) return expect( fetch('https://bar', {}) @@ -369,7 +369,7 @@ describe('request', () => { ).resolves.toEqual('foo') }) - it('accepts a response containing a buffer', () => { + it('accepts a response', () => { fetch.mockResponseOnce(new Response(Buffer.from('foo'))) return expect( fetch('https://bar', {})