summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/utils/tests/url.spec.js
blob: d842acf7db2040e0ffa10c288b040911cce12517 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

import { parse } from "../url";

describe("url", () => {
  describe("parse", () => {
    it("parses an absolute URL", () => {
      const val = parse("http://example.com:8080/path/file.js");

      expect(val.protocol).toBe("http:");
      expect(val.host).toBe("example.com:8080");
      expect(val.pathname).toBe("/path/file.js");
      expect(val.search).toBe("");
      expect(val.hash).toBe("");
    });

    it("parses an absolute URL with query params", () => {
      const val = parse("http://example.com:8080/path/file.js?param");

      expect(val.protocol).toBe("http:");
      expect(val.host).toBe("example.com:8080");
      expect(val.pathname).toBe("/path/file.js");
      expect(val.search).toBe("?param");
      expect(val.hash).toBe("");
    });

    it("parses an absolute URL with a fragment", () => {
      const val = parse("http://example.com:8080/path/file.js#hash");

      expect(val.protocol).toBe("http:");
      expect(val.host).toBe("example.com:8080");
      expect(val.pathname).toBe("/path/file.js");
      expect(val.search).toBe("");
      expect(val.hash).toBe("#hash");
    });

    it("parses an absolute URL with query params and a fragment", () => {
      const val = parse("http://example.com:8080/path/file.js?param#hash");

      expect(val.protocol).toBe("http:");
      expect(val.host).toBe("example.com:8080");
      expect(val.pathname).toBe("/path/file.js");
      expect(val.search).toBe("?param");
      expect(val.hash).toBe("#hash");
    });

    it("parses a partial URL", () => {
      const val = parse("/path/file.js");

      expect(val.protocol).toBe("");
      expect(val.host).toBe("");
      expect(val.pathname).toBe("/path/file.js");
      expect(val.search).toBe("");
      expect(val.hash).toBe("");
    });

    it("parses a partial URL with query params", () => {
      const val = parse("/path/file.js?param");

      expect(val.protocol).toBe("");
      expect(val.host).toBe("");
      expect(val.pathname).toBe("/path/file.js");
      expect(val.search).toBe("?param");
      expect(val.hash).toBe("");
    });

    it("parses a partial URL with a fragment", () => {
      const val = parse("/path/file.js#hash");

      expect(val.protocol).toBe("");
      expect(val.host).toBe("");
      expect(val.pathname).toBe("/path/file.js");
      expect(val.search).toBe("");
      expect(val.hash).toBe("#hash");
    });

    it("parses a partial URL with query params and a fragment", () => {
      const val = parse("/path/file.js?param#hash");

      expect(val.protocol).toBe("");
      expect(val.host).toBe("");
      expect(val.pathname).toBe("/path/file.js");
      expect(val.search).toBe("?param");
      expect(val.hash).toBe("#hash");
    });
  });
});