forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext-request.test.ts
More file actions
40 lines (31 loc) · 1.09 KB
/
next-request.test.ts
File metadata and controls
40 lines (31 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* @jest-environment @edge-runtime/jest-environment
*/
import { expectTypeOf } from 'expect-type'
import { NextRequest } from 'next/dist/server/web/spec-extension/request'
it('should have 1 required parameter for constructor', () => {
expect(NextRequest.length).toBe(1)
})
it('should allow the 2nd parameter to be undefined', () => {
const request = new NextRequest('https://vercel.com')
expectTypeOf(request).toMatchTypeOf<NextRequest>()
expect(new NextRequest('https://vercel.com')).toHaveProperty(
'nextUrl.pathname',
'/'
)
})
it('should clone Request with headers', () => {
const request = new Request('https://example.com', {
headers: { 'x-foo': 'bar' },
})
const nextRequest = new NextRequest(request)
expect(Object.fromEntries(nextRequest.headers)).toEqual(
Object.fromEntries(request.headers)
)
// Second argument should override headers
const headers = new Headers({ 'x-header': 'some header' })
const nextRequest2 = new NextRequest(request, { headers })
expect(Object.fromEntries(nextRequest2.headers)).toEqual(
Object.fromEntries(headers)
)
})