|
1 | 1 | import { UrlPattern } from "selenium-webdriver/bidi/urlPattern"; |
2 | 2 |
|
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; |
10 | 4 |
|
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"); |
17 | 11 |
|
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