Skip to content

Commit 99bde8e

Browse files
committed
Add tests for proxyHeaders helper
1 parent 6f8326e commit 99bde8e

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/util/proxyHeaders.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import test from "ava"
2+
3+
import {proxyHeaders} from "./proxyHeaders.js"
4+
5+
test("Properties can be accessed by their original name", t => {
6+
const object = proxyHeaders({"Content-Type": "application/json"})
7+
8+
t.is(object["Content-Type"], "application/json")
9+
})
10+
11+
test("Properties can be accessed by lowercased name", t => {
12+
const object = proxyHeaders({"Content-Type": "application/json"})
13+
14+
t.is(object["content-type"], "application/json")
15+
})
16+
17+
test("Has no affect on symbols", t => {
18+
const name = Symbol("something")
19+
20+
const object = proxyHeaders({[name]: "value"})
21+
22+
t.is(object[name], "value")
23+
})
24+
25+
test("Returns indefined if property doesn't exists", t => {
26+
const object: Record<string, string> = proxyHeaders({FOO: "foo"})
27+
28+
t.is(object.FOO, "foo")
29+
t.is(object.foo, "foo")
30+
t.is(object.bar, undefined)
31+
})
32+
33+
test("Lowercases properties can be recognized by the in operator", t => {
34+
const object = proxyHeaders({"Content-Length": "42"})
35+
36+
t.true("content-length" in object)
37+
})
38+
39+
test("Original property name can be recognized by the in operator", t => {
40+
const object = proxyHeaders({"Content-Length": "451"})
41+
42+
t.true("Content-Length" in object)
43+
})
44+
45+
test("The in operator will return false for non-existent properties", t => {
46+
const object: Record<string, string> = proxyHeaders({FOO: "foo"})
47+
48+
t.false("bar" in object)
49+
})

0 commit comments

Comments
 (0)