import { getTimezoneOffsetInMs } from './get_timezone_offset_in_ms' ; import moment from 'moment-timezone' ; describe ( 'getTimezoneOffsetInMs' , ( ) => { let originalTimezone ; beforeAll ( ( ) => { originalTimezone = moment . defaultZone ; } ) ; afterAll ( ( ) => { moment . tz . setDefault ( originalTimezone ? originalTimezone . name : '' ) ; } ) ; describe ( 'when no default timezone is set' , ( ) => { it ( 'guesses the timezone' , ( ) => { moment . tz . setDefault ( ) ; const guess = jest . fn ( ( ) => 'Etc/UTC' ) ; jest . spyOn ( moment . tz , 'guess' ) . mockImplementationOnce ( guess ) ; getTimezoneOffsetInMs ( Date . now ( ) ) ; expect ( guess ) . toHaveBeenCalled ( ) ; } ) ; } ) ; describe ( 'when a default timezone is set' , ( ) => { it ( 'returns the time in milliseconds' , ( ) => { moment . tz . setDefault ( 'America/Denver' ) ; const now = Date . now ( ) ; const expectedOffset = moment . tz . zone ( 'America/Denver' ) ! . parse ( now ) * 60000 ; expect ( getTimezoneOffsetInMs ( Date . now ( ) ) ) . toEqual ( expectedOffset ) ; } ) ; } ) ; } ) ;