@fastly/as-url
Version:
 
40 lines (32 loc) • 1.09 kB
text/typescript
// Copyright 2020 Fastly, Inc.
import { URL } from "../url";
describe("Invalid URLs that should throw an Error", () => {
test("Empty hosts should not allow special schemes (excluding file)", () => {
expect(() => {
let url = new URL("https://");
}).toThrow();
// File should be valid
let fileUrl = new URL("file://");
expect(fileUrl).toBeTruthy();
});
test("Opaque hosts should not allow special schemes (except http and https)", () => {
expect(() => {
let url = new URL("ftp://hello");
}).toThrow();
expect(() => {
let url = new URL("http://localhost");
}).toBeTruthy();
});
// A URL-port string must be one of the following:
// the empty string
// one or more ASCII digits representing a decimal number no greater than 2^16 − 1.
// https://url.spec.whatwg.org/#url-port-string
test("Will throw on port edge cases", () => {
expect(() => {
let url = new URL("https://fastly.com:0");
}).toThrow();
expect(() => {
let url = new URL("https://fastly.com:65536");
}).toThrow();
});
});