import assert from 'assert' ; import getWeekOfMonth from '.' ; describe ( 'getWeekOfMonth' , ( ) => { it ( 'returns the week of the month of the given date' , ( ) => { const result = getWeekOfMonth ( new Date ( 2017 , 10 , 15 ) ) ; assert ( result === 3 ) ; } ) ; describe ( 'edge cases' , ( ) => { describe ( 'when the given day is the first of a month' , ( ) => { it ( 'returns the week of the month of the given date' , ( ) => { const result = getWeekOfMonth ( new Date ( 2017 , 10 , 1 ) ) ; assert ( result === 1 ) ; } ) ; } ) ; describe ( 'when the given day is the last of a month #1' , ( ) => { it ( 'returns the week of the month of the given date' , ( ) => { const result = getWeekOfMonth ( new Date ( 2017 , 10 , 30 ) ) ; assert ( result === 5 ) ; } ) ; } ) ; describe ( 'when the given day is the last of a month #2' , ( ) => { it ( 'returns the week of the month of the given date' , ( ) => { const result = getWeekOfMonth ( new Date ( 2017 , 9 , 31 ) ) ; assert ( result === 5 ) ; } ) ; } ) ; } ) ; it ( 'allows to specify which day is the first day of the week' , ( ) => { const result = getWeekOfMonth ( new Date ( 2017 , 9 , 1 ) , { weekStartsOn : 1 , } ) ; assert ( result === 1 ) ; } ) ; it ( 'allows to specify which day is the first day of the week in locale' , ( ) => { const result = getWeekOfMonth ( new Date ( 2017 , 9 , 31 ) , { locale : { options : { weekStartsOn : 1 } , } , } ) ; assert ( result === 6 ) ; } ) ; it ( '`options.weekStartsOn` overwrites the first day of the week specified in locale' , ( ) => { const result = getWeekOfMonth ( new Date ( 2017 , 10 , 13 ) , { weekStartsOn : 1 , locale : { options : { weekStartsOn : 0 } , } , } ) ; assert ( result === 3 ) ; } ) ; it ( 'accepts a timestamp' , ( ) => { const result = getWeekOfMonth ( new Date ( 2017 , 10 , 1 ) . getTime ( ) ) ; assert ( result === 1 ) ; } ) ; it ( 'throws RangeError exception if `weekStartsOn` is out of bound' , ( ) => { assert . throws ( ( ) => getWeekOfMonth ( new Date ( 2019 , 4 , 5 ) , { weekStartsOn : 7 , } ) , RangeError ) ; } ) ; it ( 'returns NaN if the given date is invalid' , ( ) => { const result = getWeekOfMonth ( new Date ( NaN ) ) ; assert ( isNaN ( result ) ) ; } ) ; it ( 'throws TypeError exception if passed less than 1 argument' , ( ) => { assert . throws ( getWeekOfMonth . bind ( null ) , TypeError ) ; } ) ; it ( 'throws RangeError exception weekStartsOn is NaN' , ( ) => { assert . throws ( ( ) => getWeekOfMonth ( new Date ( 2017 , 10 , 1 ) , { weekStartsOn : NaN , } ) , RangeError ) ; } ) ; it ( 'returns the week of the month of the given date, when the given date is sunday' , ( ) => { const result = getWeekOfMonth ( new Date ( 2019 , 4 , 5 ) , { weekStartsOn : 1 , } ) ; assert ( result === 1 ) ; } ) ; } ) ;