aboutsummaryrefslogtreecommitdiff
path: root/test/js/web/url/url.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'test/js/web/url/url.test.ts')
-rw-r--r--test/js/web/url/url.test.ts66
1 files changed, 64 insertions, 2 deletions
diff --git a/test/js/web/url/url.test.ts b/test/js/web/url/url.test.ts
index 6ad691c1b..f19a132df 100644
--- a/test/js/web/url/url.test.ts
+++ b/test/js/web/url/url.test.ts
@@ -1,6 +1,19 @@
import { describe, it, expect } from "bun:test";
describe("url", () => {
+ it("URL throws", () => {
+ expect(() => new URL("")).toThrow('"" cannot be parsed as a URL');
+ expect(() => new URL(" ")).toThrow('" " cannot be parsed as a URL');
+ expect(() => new URL("boop", "http!/example.com")).toThrow(
+ '"boop" cannot be parsed as a URL against "http!/example.com"',
+ );
+
+ // redact
+ expect(() => new URL("boop", "https!!username:password@example.com")).toThrow(
+ '"boop" cannot be parsed as a URL against <redacted>',
+ );
+ });
+
it("should have correct origin and protocol", () => {
var url = new URL("https://example.com");
expect(url.protocol).toBe("https:");
@@ -39,8 +52,7 @@ describe("url", () => {
expect(url.protocol).toBe("mailto:");
expect(url.origin).toBe("null");
});
- it.skip("should work with blob urls", () => {
- // TODO
+ it("blob urls", () => {
var url = new URL("blob:https://example.com/1234-5678");
expect(url.protocol).toBe("blob:");
expect(url.origin).toBe("https://example.com");
@@ -59,6 +71,9 @@ describe("url", () => {
url = new URL("blob:ws://example.com");
expect(url.protocol).toBe("blob:");
expect(url.origin).toBe("ws://example.com");
+ url = new URL("blob:file:///folder/else/text.txt");
+ expect(url.protocol).toBe("blob:");
+ expect(url.origin).toBe("file://");
});
it("prints", () => {
expect(Bun.inspect(new URL("https://example.com"))).toBe(`URL {
@@ -165,4 +180,51 @@ describe("url", () => {
expect(result.username).toBe(values.username);
}
});
+
+ describe("URL.canParse", () => {
+ (
+ [
+ {
+ "url": undefined,
+ "base": undefined,
+ "expected": false,
+ },
+ {
+ "url": "a:b",
+ "base": undefined,
+ "expected": true,
+ },
+ {
+ "url": undefined,
+ "base": "a:b",
+ "expected": false,
+ },
+ {
+ "url": "a:/b",
+ "base": undefined,
+ "expected": true,
+ },
+ {
+ "url": undefined,
+ "base": "a:/b",
+ "expected": true,
+ },
+ {
+ "url": "https://test:test",
+ "base": undefined,
+ "expected": false,
+ },
+ {
+ "url": "a",
+ "base": "https://b/",
+ "expected": true,
+ },
+ ] as const
+ ).forEach(({ url, base, expected }) => {
+ it(`URL.canParse(${url}, ${base})`, () => {
+ // @ts-expect-error
+ expect(URL.canParse(url, base)).toBe(expected);
+ });
+ });
+ });
});