@@ -9,38 +9,43 @@ describe('getURLVideoID()', () => {
99
1010 it ( 'Retrives the video ID from the url' , ( ) => {
1111 let id ;
12- id = getVideoID ( 'http://www.youtube.com/watch?v=RAW_VIDEOID' ) ;
12+ id = getURLVideoID ( 'http://www.youtube.com/watch?v=RAW_VIDEOID' ) ;
1313 assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
14- id = getVideoID ( 'http://youtu.be/RAW_VIDEOID' ) ;
14+ id = getURLVideoID ( 'http://youtu.be/RAW_VIDEOID' ) ;
1515 assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
16- id = getVideoID ( 'http://youtube.com/v/RAW_VIDEOID' ) ;
16+ id = getURLVideoID ( 'http://youtube.com/v/RAW_VIDEOID' ) ;
1717 assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
18- id = getVideoID ( 'http://youtube.com/embed/RAW_VIDEOID' ) ;
18+ id = getURLVideoID ( 'http://youtube.com/embed/RAW_VIDEOID' ) ;
1919 assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
20- id = getVideoID ( 'http://youtube.com/shorts/RAW_VIDEOID' ) ;
20+ id = getURLVideoID ( 'http://youtube.com/shorts/RAW_VIDEOID' ) ;
2121 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' ) ;
2323 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' ) ;
2525 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' ) ;
2727 assert . strictEqual ( id , 'RAW_VIDEOID' ) ;
2828 assert . throws ( ( ) => {
29- getVideoID ( 'https://any.youtube.com/watch?v=RAW_VIDEOID' ) ;
29+ getURLVideoID ( 'https://any.youtube.com/watch?v=RAW_VIDEOID' ) ;
3030 } , / N o t a Y o u T u b e d o m a i n / ) ;
3131 assert . throws ( ( ) => {
32- getVideoID ( 'https://www.twitch.tv/user/v/1234' ) ;
32+ getURLVideoID ( 'https://www.twitch.tv/user/v/1234' ) ;
3333 } , / N o t a Y o u T u b e d o m a i n / ) ;
3434 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 / ) ;
3737 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 + " / ) ;
4040 assert . throws ( ( ) => {
41- getVideoID ( 'http://www.youtube.com/watch?v=asdf$%^ddf-' ) ;
41+ getURLVideoID ( 'http://www.youtube.com/watch?v=asdf$%^ddf-' ) ;
4242 } , / 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 / ) ;
4343 } ) ;
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+ } ) ;
4449} ) ;
4550
4651
@@ -78,6 +83,11 @@ describe('getVideoID()', () => {
7883 getVideoID ( 'http://www.youtube.com/playlist?list=1337' ) ;
7984 } , / N o v i d e o i d f o u n d : \S + / ) ;
8085 } ) ;
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+ } ) ;
8191} ) ;
8292
8393
0 commit comments