@@ -5,6 +5,66 @@ const basicUrl = "https://google.com/search/index.html?q=test&p=123#hash";
55 * /bin/bash test.sh tests/url/001_url.unit.ts
66 */
77
8+ // throws
9+ // FAIL test tests/url/001_url.unit.ts > simples
10+ // TypeError: Invalid URL
11+ // ❯ tests/url/001_url.unit.ts:9:13
12+ // 7|
13+ // 8| test('simples', () => {
14+ // 9| const u = new URL('google.com');
15+ // | ^
16+ // 10| })
17+ // 11|
18+ describe ( "errors" , ( ) => {
19+ test ( "empty string" , ( ) => {
20+ try {
21+ const u = new URL ( "" ) ;
22+
23+ throw new Error ( `Shouldn't happen` ) ;
24+ } catch ( e ) {
25+ expect ( String ( e ) ) . toBe ( "TypeError: Invalid URL" ) ;
26+ expect ( e . input ) . toBe ( "" ) ;
27+ expect ( e . code ) . toBe ( "ERR_INVALID_URL" ) ;
28+ }
29+ } ) ;
30+
31+ test ( "just hostname" , ( ) => {
32+ try {
33+ const u = new URL ( "google.com" ) ;
34+
35+ throw new Error ( `Shouldn't happen` ) ;
36+ } catch ( e ) {
37+ expect ( String ( e ) ) . toBe ( "TypeError: Invalid URL" ) ;
38+ expect ( e . input ) . toBe ( "google.com" ) ;
39+ expect ( e . code ) . toBe ( "ERR_INVALID_URL" ) ;
40+ }
41+ } ) ;
42+
43+ test ( "just hostname" , ( ) => {
44+ try {
45+ const u = new URL ( "//google.com" ) ;
46+
47+ throw new Error ( `Shouldn't happen` ) ;
48+ } catch ( e ) {
49+ expect ( String ( e ) ) . toBe ( "TypeError: Invalid URL" ) ;
50+ expect ( e . input ) . toBe ( "//google.com" ) ;
51+ expect ( e . code ) . toBe ( "ERR_INVALID_URL" ) ;
52+ }
53+ } ) ;
54+
55+ test ( "just get params" , ( ) => {
56+ try {
57+ const u = new URL ( "a=b&c=d" ) ;
58+
59+ throw new Error ( `Shouldn't happen` ) ;
60+ } catch ( e ) {
61+ expect ( String ( e ) ) . toBe ( "TypeError: Invalid URL" ) ;
62+ expect ( e . input ) . toBe ( "a=b&c=d" ) ;
63+ expect ( e . code ) . toBe ( "ERR_INVALID_URL" ) ;
64+ }
65+ } ) ;
66+ } ) ;
67+
868describe ( "hash" , ( ) => {
969 test ( "get hash" , ( ) => {
1070 const u = new URL ( basicUrl ) ;
@@ -74,9 +134,15 @@ describe("search params", () => {
74134
75135 u . searchParams . delete ( "a" ) ;
76136
77- expect ( u . toString ( ) ) . toBe ( "https://google.com/search/index.html?q=test&p=123#hash" ) ;
78-
79- expect ( u . toJSON ( ) ) . toBe ( "https://google.com/search/index.html?q=test&p=123#hash" ) ;
137+ expect ( {
138+ a : u . toString ( ) ,
139+ b : u . toJSON ( ) ,
140+ c : u . href ,
141+ } ) . toEqual ( {
142+ a : "https://google.com/search/index.html?q=test&p=123#hash" ,
143+ b : "https://google.com/search/index.html?q=test&p=123#hash" ,
144+ c : "https://google.com/search/index.html?q=test&p=123#hash" ,
145+ } ) ;
80146 } ) ;
81147
82148 test ( "change just params" , ( ) => {
0 commit comments