@@ -9,38 +9,43 @@ describe('getURLVideoID()', () => {
9
9
10
10
it ( 'Retrives the video ID from the url' , ( ) => {
11
11
let id ;
12
- id = getVideoID ( 'http://www.youtube.com/watch?v=RAW_VIDEOID' ) ;
12
+ id = getURLVideoID ( 'http://www.youtube.com/watch?v=RAW_VIDEOID' ) ;
13
13
assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
14
- id = getVideoID ( 'http://youtu.be/RAW_VIDEOID' ) ;
14
+ id = getURLVideoID ( 'http://youtu.be/RAW_VIDEOID' ) ;
15
15
assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
16
- id = getVideoID ( 'http://youtube.com/v/RAW_VIDEOID' ) ;
16
+ id = getURLVideoID ( 'http://youtube.com/v/RAW_VIDEOID' ) ;
17
17
assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
18
- id = getVideoID ( 'http://youtube.com/embed/RAW_VIDEOID' ) ;
18
+ id = getURLVideoID ( 'http://youtube.com/embed/RAW_VIDEOID' ) ;
19
19
assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
20
- id = getVideoID ( 'http://youtube.com/shorts/RAW_VIDEOID' ) ;
20
+ id = getURLVideoID ( 'http://youtube.com/shorts/RAW_VIDEOID' ) ;
21
21
assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
22
- id = getVideoID ( 'http://youtube.com/v/RAW_VIDEOID/FakeVideoID' ) ;
22
+ id = getURLVideoID ( 'http://youtube.com/v/RAW_VIDEOID/FakeVideoID' ) ;
23
23
assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
24
- id = getVideoID ( 'https://music.youtube.com/watch?v=RAW_VIDEOID&list=RDAMVMmtLgabce8KQ' ) ;
24
+ id = getURLVideoID ( 'https://music.youtube.com/watch?v=RAW_VIDEOID&list=RDAMVMmtLgabce8KQ' ) ;
25
25
assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
26
- id = getVideoID ( 'https://gaming.youtube.com/watch?v=RAW_VIDEOID' ) ;
26
+ id = getURLVideoID ( 'https://gaming.youtube.com/watch?v=RAW_VIDEOID' ) ;
27
27
assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
28
28
assert . throws ( ( ) => {
29
- getVideoID ( 'https://any.youtube.com/watch?v=RAW_VIDEOID' ) ;
29
+ getURLVideoID ( 'https://any.youtube.com/watch?v=RAW_VIDEOID' ) ;
30
30
} , / N o t a Y o u T u b e d o m a i n / ) ;
31
31
assert . throws ( ( ) => {
32
- getVideoID ( 'https://www.twitch.tv/user/v/1234' ) ;
32
+ getURLVideoID ( 'https://www.twitch.tv/user/v/1234' ) ;
33
33
} , / N o t a Y o u T u b e d o m a i n / ) ;
34
34
assert . throws ( ( ) => {
35
- getVideoID ( 'www.youtube.com' ) ;
36
- } , / N o v i d e o i d f o u n d : \S + / ) ;
35
+ getURLVideoID ( 'www.youtube.com' ) ;
36
+ } , / I n v a l i d U R L / ) ;
37
37
assert . throws ( ( ) => {
38
- getVideoID ( 'http://www.youtube.com/playlist?list=1337' ) ;
39
- } , / N o v i d e o i d f o u n d : \S + / ) ;
38
+ getURLVideoID ( 'http://www.youtube.com/playlist?list=1337' ) ;
39
+ } , / N o v i d e o i d f o u n d : " \S + " / ) ;
40
40
assert . throws ( ( ) => {
41
- getVideoID ( 'http://www.youtube.com/watch?v=asdf$%^ddf-' ) ;
41
+ getURLVideoID ( 'http://www.youtube.com/watch?v=asdf$%^ddf-' ) ;
42
42
} , / V i d e o i d \( [ ^ ) ] + \) d o e s n o t m a t c h e x p e c t e d f o r m a t / ) ;
43
43
} ) ;
44
+
45
+ it ( 'Ignores surrounding whitespaces' , ( ) => {
46
+ let id = getURLVideoID ( '\n\t http://www.youtube.com/watch?v=RAW_VIDEOID ' ) ;
47
+ assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
48
+ } ) ;
44
49
} ) ;
45
50
46
51
@@ -78,6 +83,11 @@ describe('getVideoID()', () => {
78
83
getVideoID ( 'http://www.youtube.com/playlist?list=1337' ) ;
79
84
} , / N o v i d e o i d f o u n d : \S + / ) ;
80
85
} ) ;
86
+
87
+ it ( 'Ignores surrounding whitespaces' , ( ) => {
88
+ let id = getVideoID ( '\n\t http://www.youtube.com/watch?v=RAW_VIDEOID ' ) ;
89
+ assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
90
+ } ) ;
81
91
} ) ;
82
92
83
93
0 commit comments