From c640f245b9bdbdaa8f3703293dd6f4a8e4714b81 Mon Sep 17 00:00:00 2001 From: Rhys Evans Date: Wed, 24 Jul 2024 22:49:44 +0100 Subject: [PATCH] test: added test for Response.error() --- packages/core/src/Router.js | 1 - .../FetchMock/response-negotiation.test.js | 15 +++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/core/src/Router.js b/packages/core/src/Router.js index 52b10657..e77fcd22 100644 --- a/packages/core/src/Router.js +++ b/packages/core/src/Router.js @@ -210,7 +210,6 @@ export default class Router { // eslint-disable-next-line class-methods-use-this async generateResponse(callLog) { const responseInput = await resolveUntilResponseConfig(callLog); - // If the response is a pre-made Response, respond with it if (responseInput instanceof Response) { return { diff --git a/packages/core/src/__tests__/FetchMock/response-negotiation.test.js b/packages/core/src/__tests__/FetchMock/response-negotiation.test.js index a930a3e7..bf4191bf 100644 --- a/packages/core/src/__tests__/FetchMock/response-negotiation.test.js +++ b/packages/core/src/__tests__/FetchMock/response-negotiation.test.js @@ -116,18 +116,21 @@ describe('response negotiation', () => { }); it('Response', async () => { - fm.route( - 'http://a.com/', - new fm.config.Response('http://a.com/', { status: 200 }), - ); + fm.route('http://a.com/', new Response('http://a.com/', { status: 200 })); const res = await fm.fetchHandler('http://a.com/'); expect(res.status).toEqual(200); }); + it('should work with Response.error()', async () => { + fm.route('http://a.com', Response.error()); + const response = await fm.fetchHandler('http://a.com'); + expect(response.status).toBe(0); + }); + it('function that returns a Response', async () => { fm.route( 'http://a.com/', - () => new fm.config.Response('http://a.com/', { status: 200 }), + () => new Response('http://a.com/', { status: 200 }), ); const res = await fm.fetchHandler('http://a.com/'); expect(res.status).toEqual(200); @@ -136,7 +139,7 @@ describe('response negotiation', () => { it('Promise that returns a Response', async () => { fm.route( 'http://a.com/', - Promise.resolve(new fm.config.Response('http://a.com/', { status: 200 })), + Promise.resolve(new Response('http://a.com/', { status: 200 })), ); const res = await fm.fetchHandler('http://a.com/'); expect(res.status).toEqual(200);