Skip to content

Commit 6b163f4

Browse files
committed
test: add unit tests for getRequestURL function
1 parent 9c770ca commit 6b163f4

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { describe, expect, it } from "vitest";
2+
import { getRequestURL } from "./index";
3+
4+
describe("getUrl", () => {
5+
it("should return URL object for the request", () => {
6+
const request = new Request("https://example.com/path?query=test");
7+
const url = getRequestURL(request);
8+
expect(url).toBeInstanceOf(URL);
9+
expect(url.href).toBe("https://example.com/path?query=test");
10+
});
11+
12+
it("should cache URL object on subsequent calls", () => {
13+
const request = new Request("https://example.com/path?query=test");
14+
const firstUrl = getRequestURL(request);
15+
const secondUrl = getRequestURL(request);
16+
expect(firstUrl).toBe(secondUrl);
17+
});
18+
19+
it("should handle different request URLs", () => {
20+
const request1 = new Request("https://example.com/path1");
21+
const request2 = new Request("https://example.com/path2");
22+
23+
const url1 = getRequestURL(request1);
24+
const url2 = getRequestURL(request2);
25+
26+
expect(url1.pathname).toBe("/path1");
27+
expect(url2.pathname).toBe("/path2");
28+
});
29+
});

0 commit comments

Comments
 (0)