Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/adapters/_node/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 13 additions & 1 deletion test/_fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
14 changes: 13 additions & 1 deletion test/_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down