diff --git a/src/adapters/_node/request.ts b/src/adapters/_node/request.ts index e7a35a8..654e7f1 100644 --- a/src/adapters/_node/request.ts +++ b/src/adapters/_node/request.ts @@ -26,7 +26,11 @@ export const NodeRequest: { // @ts-expect-error static [Symbol.hasInstance](instance) { - return instance instanceof NativeRequest; + if (this === PatchedRequest) { + return instance instanceof NativeRequest; + } else { + return Object.prototype.isPrototypeOf.call(this.prototype, instance); + } } constructor( diff --git a/test/_fixture.ts b/test/_fixture.ts index beb19fd..e90dd07 100644 --- a/test/_fixture.ts +++ b/test/_fixture.ts @@ -102,7 +102,19 @@ export const fixture: ( return new _Response(`ip: ${req.ip}`); } case "/req-instanceof": { - return new _Response(req instanceof Request ? "yes" : "no"); + class MyRequst extends Request {} + return Response.json({ + instanceofRequest: req instanceof Request ? "yes" : "no", + instanceofExtended: req instanceof MyRequst ? "yes" : "no", + }); + } + case "/extended-req-instanceof": { + class MyRequst extends Request {} + const myReq = new MyRequst("http://example.com"); + return Response.json({ + instanceofRequest: myReq instanceof Request ? "yes" : "no", + instanceofExtended: myReq instanceof MyRequst ? "yes" : "no", + }); } case "/req-headers-instanceof": { return new _Response(req.headers instanceof Headers ? "yes" : "no"); diff --git a/test/_tests.ts b/test/_tests.ts index 5fb05a8..3329317 100644 --- a/test/_tests.ts +++ b/test/_tests.ts @@ -24,7 +24,19 @@ export function addTests(opts: { test("request instanceof Request", async () => { const response = await fetch(url("/req-instanceof")); expect(response.status).toBe(200); - expect(await response.text()).toMatch("yes"); + expect(await response.json()).toMatchObject({ + instanceofRequest: "yes", + instanceofExtended: "no", + }); + }); + + test("extended request instanceof Request", async () => { + const response = await fetch(url("/extended-req-instanceof")); + expect(response.status).toBe(200); + expect(await response.json()).toMatchObject({ + instanceofRequest: "yes", + instanceofExtended: "yes", + }); }); test("request.headers instanceof Headers", async () => {