import assert from 'assert' ; import eachWeekOfInterval from '.' ; describe ( 'eachWeekOfInterval' , ( ) => { it ( 'returns an array with starts of weeks from the week of the start date to the week of the end date' , ( ) => { const result = eachWeekOfInterval ( { start : new Date ( 2014 , 9 , 6 ) , end : new Date ( 2014 , 10 , 23 ) , } ) ; assert . deepStrictEqual ( result , [ new Date ( 2014 , 9 , 5 ) , new Date ( 2014 , 9 , 12 ) , new Date ( 2014 , 9 , 19 ) , new Date ( 2014 , 9 , 26 ) , new Date ( 2014 , 10 , 2 ) , new Date ( 2014 , 10 , 9 ) , new Date ( 2014 , 10 , 16 ) , new Date ( 2014 , 10 , 23 ) , ] ) ; } ) ; it ( 'accepts timestamps' , ( ) => { const result = eachWeekOfInterval ( { start : new Date ( 2014 , 9 , 6 ) . getTime ( ) , end : new Date ( 2014 , 10 , 23 ) . getTime ( ) , } ) ; assert . deepStrictEqual ( result , [ new Date ( 2014 , 9 , 5 ) , new Date ( 2014 , 9 , 12 ) , new Date ( 2014 , 9 , 19 ) , new Date ( 2014 , 9 , 26 ) , new Date ( 2014 , 10 , 2 ) , new Date ( 2014 , 10 , 9 ) , new Date ( 2014 , 10 , 16 ) , new Date ( 2014 , 10 , 23 ) , ] ) ; } ) ; it ( 'handles the dates that are not starts/ends of days and weeks' , ( ) => { const result = eachWeekOfInterval ( { start : new Date ( 2014 , 9 , 6 , 6 , 35 ) , end : new Date ( 2014 , 10 , 25 , 22 , 16 ) , } ) ; assert . deepStrictEqual ( result , [ new Date ( 2014 , 9 , 5 ) , new Date ( 2014 , 9 , 12 ) , new Date ( 2014 , 9 , 19 ) , new Date ( 2014 , 9 , 26 ) , new Date ( 2014 , 10 , 2 ) , new Date ( 2014 , 10 , 9 ) , new Date ( 2014 , 10 , 16 ) , new Date ( 2014 , 10 , 23 ) , ] ) ; } ) ; it ( 'considers the weekStartsOn option' , ( ) => { const result = eachWeekOfInterval ( { start : new Date ( 2014 , 9 , 6 , 6 , 35 ) , end : new Date ( 2014 , 10 , 25 , 22 , 15 ) , } , { weekStartsOn : 2 } ) ; assert . deepStrictEqual ( result , [ new Date ( 2014 , 8 , 30 ) , new Date ( 2014 , 9 , 7 ) , new Date ( 2014 , 9 , 14 ) , new Date ( 2014 , 9 , 21 ) , new Date ( 2014 , 9 , 28 ) , new Date ( 2014 , 10 , 4 ) , new Date ( 2014 , 10 , 11 ) , new Date ( 2014 , 10 , 18 ) , new Date ( 2014 , 10 , 25 ) , ] ) ; } ) ; it ( 'returns one week if the both arguments are on the same week' , ( ) => { const result = eachWeekOfInterval ( { start : new Date ( 2014 , 9 , 6 , 14 ) , end : new Date ( 2014 , 9 , 8 , 15 ) , } ) ; assert . deepStrictEqual ( result , [ new Date ( 2014 , 9 , 5 ) ] ) ; } ) ; it ( 'returns one day if the both arguments are the same' , ( ) => { const result = eachWeekOfInterval ( { start : new Date ( 2014 , 9 , 6 , 14 ) , end : new Date ( 2014 , 9 , 6 , 14 ) , } ) ; assert . deepStrictEqual ( result , [ new Date ( 2014 , 9 , 5 ) ] ) ; } ) ; it ( 'throws an exception if the start date is after the end date' , ( ) => { const block = eachWeekOfInterval . bind ( null , { start : new Date ( 2014 , 9 , 12 ) , end : new Date ( 2014 , 9 , 6 ) , } ) ; assert . throws ( block , RangeError ) ; } ) ; it ( 'throws an exception if the start date is `Invalid Date`' , ( ) => { const block = eachWeekOfInterval . bind ( null , { start : new Date ( NaN ) , end : new Date ( 2014 , 9 , 6 ) , } ) ; assert . throws ( block , RangeError ) ; } ) ; it ( 'throws an exception if the end date is `Invalid Date`' , ( ) => { const block = eachWeekOfInterval . bind ( null , { start : new Date ( 2014 , 9 , 12 ) , end : new Date ( NaN ) , } ) ; assert . throws ( block , RangeError ) ; } ) ; it ( 'throws an exception if the interval is undefined' , ( ) => { const block = ( ) => eachWeekOfInterval ( undefined ) ; assert . throws ( block , RangeError ) ; } ) ; it ( 'throws `RangeError` if `options.weekStartsOn` is not convertible to 0, 1, ..., 6 or undefined' , ( ) => { const block = ( ) => eachWeekOfInterval ( { start : new Date ( 2014 , 9 , 6 , 6 , 35 ) , end : new Date ( 2014 , 10 , 25 , 22 , 15 ) , } , { weekStartsOn : NaN , } ) ; assert . throws ( block , RangeError ) ; } ) ; it ( 'throws TypeError exception if passed less than 1 argument' , ( ) => { assert . throws ( eachWeekOfInterval . bind ( null ) , TypeError ) ; } ) ; } ) ;