Skip to content

Commit

Permalink
fix: improve NextRequest mock json handling
Browse files Browse the repository at this point in the history
Co-Authored-By: ben <ben@prologe.io>
  • Loading branch information
devin-ai-integration[bot] and benjaminshafii committed Dec 25, 2024
1 parent 4250cb8 commit 4aebfce
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/web/__mocks__/next/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ interface NextRequestInit extends RequestInit {

export class NextRequest extends Request {
private _url: string;
private _body: any;

constructor(input: RequestInfo | URL, init?: NextRequestInit) {
super(input, init);
Object.setPrototypeOf(this, NextRequest.prototype);
this._url = input instanceof URL ? input.href : input.toString();
try {
this._body = init?.body ? JSON.parse(init.body.toString()) : {};
} catch (e) {
this._body = {};
}
}

json<T = any>(): Promise<T> {
return super.json();
json(): Promise<any> {
return Promise.resolve(this._body);
}

// Add other required Next.js Request methods
Expand Down

0 comments on commit 4aebfce

Please sign in to comment.