Skip to content

Commit

Permalink
fix(fetch): correctly intercept requests with URL inputs
Browse files Browse the repository at this point in the history
If `input` (first argument to fetch) is not a string, then
it can be a URL, which does not have a `.url` property
but does have a `.href` property

This fixes a type error and also fixes tests that
were failing in Node 18 without this fix.
  • Loading branch information
milesrichardson committed Aug 29, 2022
1 parent 1c4309e commit eb46b83
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/interceptors/fetch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ export class FetchInterceptor extends Interceptor<HttpRequestEventMap> {
globalThis.fetch = async (input, init) => {
const request = new Request(input, init)

const url = typeof input === 'string' ? input : input.url
const url =
typeof input === 'string'
? input
: input instanceof URL
? input.href
: input.url

const method = request.method

this.log('[%s] %s', method, url)
Expand Down

0 comments on commit eb46b83

Please sign in to comment.