From 6c551494ce3f3903e125c5f47bedcf7856ac1639 Mon Sep 17 00:00:00 2001 From: Rhys Evans Date: Sat, 15 Jun 2024 20:47:46 +0100 Subject: [PATCH] match fetch when called with a string object --- src/lib/request-utils.js | 1 + test/specs/routing/url-matching.test.js | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/lib/request-utils.js b/src/lib/request-utils.js index 2726d8c0..1d0c99e5 100644 --- a/src/lib/request-utils.js +++ b/src/lib/request-utils.js @@ -63,6 +63,7 @@ export function normalizeRequest(url, options, Request) { } if ( typeof url === 'string' || + url instanceof String || // horrible URL object duck-typing (typeof url === 'object' && 'href' in url) ) { diff --git a/test/specs/routing/url-matching.test.js b/test/specs/routing/url-matching.test.js index 91e9600a..d62d2cc8 100644 --- a/test/specs/routing/url-matching.test.js +++ b/test/specs/routing/url-matching.test.js @@ -23,6 +23,12 @@ describe('url matching', () => { expect(fm.calls(true).length).toEqual(2); }); + it('match string objects', async () => { + fm.mock('http://a.com/path', 200).catch(); + await fm.fetchHandler(new String('http://a.com/path')); // eslint-disable-line no-new-wrappers + expect(fm.calls(true).length).toEqual(1); + }); + it('match exact strings with relative url', async () => { fm.mock('/path', 200).catch(); await fm.fetchHandler('/pat');