-
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathURLPattern.js
More file actions
49 lines (42 loc) · 1.45 KB
/
URLPattern.js
File metadata and controls
49 lines (42 loc) · 1.45 KB
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
describe("URLPattern", function () {
it("throws on invalid URLPattern", function () {
var exceptionCaught = false;
try {
const pattern = new URLPattern(null);
} catch (e) {
exceptionCaught = true;
}
expect(exceptionCaught).toBe(true);
});
it("does not throw on valid URLPattern", function () {
var exceptionCaught = false;
try {
const pattern = new URLPattern("https://example.com/books/:id");
} catch (e) {
exceptionCaught = true;
}
expect(exceptionCaught).toBe(false);
});
it("parses simple pattern", function () {
const pattern = new URLPattern("https://example.com/books/:id");
expect(pattern.protocol).toBe("https:");
expect(pattern.hostname).toBe("example.com");
expect(pattern.pathname).toBe("/books/:id");
expect(pattern.port).toBe("");
expect(pattern.search).toBe("*");
expect(pattern.hash).toBe("*");
expect(pattern.username).toBe("*");
expect(pattern.password).toBe("*");
expect(pattern.hasRegExpGroups).toBe(false);
});
it("parses with undefined base", function () {
const pattern = new URLPattern("https://google.com", undefined);
expect(pattern.protocol).toBe("https:");
expect(pattern.hostname).toBe("google.com");
});
it("parses with null base", function () {
const pattern = new URLPattern("https://google.com", null);
expect(pattern.protocol).toBe("https:");
expect(pattern.hostname).toBe("google.com");
});
});