summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/src/utils/tests/path.spec.js
blob: 58bdf046f0afe9a1ec4efeac0a4340480a58011b (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
/* 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 { basename, dirname, isURL, isAbsolute, join } from "../path";

const fullTestURL = "https://www.example.com/some/endpoint";
const absoluteTestPath = "/some/absolute/path/to/resource";
const aTestName = "name";

describe("basename()", () => {
  it("returns the basename of the path", () => {
    expect(basename(fullTestURL)).toBe("endpoint");
  });
});

describe("dirname()", () => {
  it("returns the current directory in a path", () => {
    expect(dirname(fullTestURL)).toBe("https://www.example.com/some");
  });
});

describe("isURL()", () => {
  it("returns true if a string contains characters denoting a scheme", () => {
    expect(isURL(fullTestURL)).toBe(true);
  });

  it("returns false if string does not denote a scheme", () => {
    expect(isURL(absoluteTestPath)).toBe(false);
  });
});

describe("isAbsolute()", () => {
  it("returns true if a string begins with a slash", () => {
    expect(isAbsolute(absoluteTestPath)).toBe(true);
  });

  it("returns false if a string does not begin with a slash", () => {
    expect(isAbsolute(fullTestURL)).toBe(false);
  });
});

describe("join()", () => {
  it("concatenates a base path and a directory name", () => {
    expect(join(absoluteTestPath, aTestName)).toBe(
      "/some/absolute/path/to/resource/name"
    );
  });
});