UNPKG

1.09 kBPlain TextView Raw
1// Copyright 2020 Fastly, Inc.
2
3import { URL } from "../url";
4
5describe("Invalid URLs that should throw an Error", () => {
6 test("Empty hosts should not allow special schemes (excluding file)", () => {
7 expect(() => {
8 let url = new URL("https://");
9 }).toThrow();
10
11 // File should be valid
12 let fileUrl = new URL("file://");
13 expect(fileUrl).toBeTruthy();
14 });
15
16 test("Opaque hosts should not allow special schemes (except http and https)", () => {
17 expect(() => {
18 let url = new URL("ftp://hello");
19 }).toThrow();
20
21 expect(() => {
22 let url = new URL("http://localhost");
23 }).toBeTruthy();
24 });
25
26 // A URL-port string must be one of the following:
27 // the empty string
28 // one or more ASCII digits representing a decimal number no greater than 2^16 − 1.
29 // https://url.spec.whatwg.org/#url-port-string
30 test("Will throw on port edge cases", () => {
31 expect(() => {
32 let url = new URL("https://fastly.com:0");
33 }).toThrow();
34
35 expect(() => {
36 let url = new URL("https://fastly.com:65536");
37 }).toThrow();
38 });
39});