Skip to content

Commit 5b92222

Browse files
authored
🤖 Merge PR DefinitelyTyped#73834 feat(selenium-webdriver): add jsdoc for urlPattern, simplify test by @hkleungai
1 parent cef76e8 commit 5b92222

File tree

2 files changed

+39
-71
lines changed

2 files changed

+39
-71
lines changed

‎types/selenium-webdriver/bidi/urlPattern.d.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,42 @@
1+
/**
2+
* Represents a URL pattern to intercept.
3+
* Described in network.UrlPatternPattern https://w3c.github.io/webdriver-bidi/#type-network-UrlPattern
4+
*/
15
declare class UrlPattern {
6+
/**
7+
* Sets the protocol for the URL pattern.
8+
* @param protocol - The protocol to set.
9+
* @returns Returns the updated instance of the URL pattern for chaining.
10+
*/
211
protocol(protocol: string): UrlPattern;
312

13+
/**
14+
* Sets the hostname for the URL pattern.
15+
* @param hostname - The hostname to set.
16+
* @returns Returns the updated instance of the URL pattern for chaining.
17+
*/
418
hostname(hostname: string): UrlPattern;
519

20+
/**
21+
* Sets the port for the URL pattern.
22+
* @param port - The port number to set.
23+
* @returns Returns the updated instance of the URL pattern for chaining.
24+
* @throws Throws an error if the port is not a number.
25+
*/
626
port(port: number): UrlPattern;
727

28+
/**
29+
* Sets the pathname for the URL pattern.
30+
* @param pathname - The pathname to set.
31+
* @returns Returns the updated instance of the URL pattern for chaining.
32+
*/
833
pathname(pathname: string): UrlPattern;
934

35+
/**
36+
* Sets the search parameter in the URL pattern.
37+
* @param search - The search parameter to be set.
38+
* @returns Returns the updated instance of the URL pattern for chaining.
39+
*/
1040
search(search: string): UrlPattern;
1141

1242
asMap(): Map<string, string>;
Lines changed: 9 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,13 @@
11
import { UrlPattern } from "selenium-webdriver/bidi/urlPattern";
22

3-
function testMethodChaining() {
4-
const urlPattern = new UrlPattern()
5-
.protocol("https")
6-
.hostname("example.com")
7-
.port(8080)
8-
.pathname("/home")
9-
.search("?query=123");
3+
let urlPattern: UrlPattern;
104

11-
if (!(urlPattern instanceof UrlPattern)) {
12-
console.error("Failed: Method chaining does not return UrlPattern");
13-
} else {
14-
console.log("Passed: Method chaining works as expected");
15-
}
16-
}
5+
urlPattern = new UrlPattern()
6+
.protocol("https")
7+
.hostname("example.com")
8+
.port(8080)
9+
.pathname("/home")
10+
.search("?query=123");
1711

18-
function testAsMap() {
19-
const urlPattern = new UrlPattern()
20-
.protocol("https")
21-
.hostname("example.com")
22-
.port(8080)
23-
.pathname("/home")
24-
.search("?query=123");
25-
26-
const map = urlPattern.asMap();
27-
if (!(map instanceof Map)) {
28-
console.error("Failed: asMap() does not return a Map");
29-
} else if (map.get("protocol") !== "https" || map.get("hostname") !== "example.com") {
30-
console.error("Failed: Map does not contain expected values");
31-
} else {
32-
console.log("Passed: asMap() returns the correct Map with expected values");
33-
}
34-
}
35-
36-
function testParameterTypes() {
37-
const urlPattern = new UrlPattern();
38-
39-
try {
40-
urlPattern.protocol("http"); // Valid type
41-
urlPattern.hostname("localhost"); // Valid type
42-
urlPattern.port(8080); // Valid type
43-
urlPattern.pathname("/test"); // Valid type
44-
urlPattern.search("?id=123"); // Valid type
45-
46-
console.log("Passed: Method parameters are correctly typed");
47-
} catch (e) {
48-
console.error("Failed: Method parameters typing issue", e);
49-
}
50-
}
51-
52-
function testMapTypes() {
53-
const urlPattern = new UrlPattern()
54-
.protocol("https")
55-
.hostname("example.com")
56-
.port(8080)
57-
.pathname("/home")
58-
.search("?query=123");
59-
60-
const result = urlPattern.asMap();
61-
const protocol = result.get("protocol");
62-
const port = result.get("port");
63-
64-
if (typeof protocol !== "string" || typeof port !== "string") {
65-
console.error("Failed: Map return types are not correct");
66-
} else {
67-
console.log("Passed: Map return types are correct");
68-
}
69-
}
70-
71-
// Run tests
72-
testMethodChaining();
73-
testAsMap();
74-
testParameterTypes();
75-
testMapTypes();
12+
// $ExpectType Map<string, string>
13+
urlPattern.asMap();

0 commit comments

Comments
 (0)