(
method = 'GET',
body?: unknown,
headers: Record<string, string> = {},
url = 'http://localhost:3000/api/test'
)
| 27 | type NextRequestInit = NonNullable<ConstructorParameters<typeof NextRequest>[1]> |
| 28 | |
| 29 | export function createMockRequest( |
| 30 | method = 'GET', |
| 31 | body?: unknown, |
| 32 | headers: Record<string, string> = {}, |
| 33 | url = 'http://localhost:3000/api/test' |
| 34 | ): NextRequest { |
| 35 | const init: NextRequestInit = { |
| 36 | method, |
| 37 | headers: new Headers({ |
| 38 | 'Content-Type': 'application/json', |
| 39 | ...headers, |
| 40 | }), |
| 41 | } |
| 42 | |
| 43 | if (body !== undefined) { |
| 44 | init.body = JSON.stringify(body) |
| 45 | } |
| 46 | |
| 47 | return new NextRequest(new URL(url), init) |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Creates a mock NextRequest with form data for file upload testing. |
no outgoing calls