fix: throw error instead of returning it RailwayTimeConversion (#1625)

This commit is contained in:
Piotr Idzik
2024-03-02 08:54:46 +01:00
committed by GitHub
parent 8734dfccf9
commit 894a46ca67
2 changed files with 5 additions and 1 deletions

View File

@ -18,7 +18,7 @@
const RailwayTimeConversion = (timeString) => {
// firstly, check that input is a string or not.
if (typeof timeString !== 'string') {
return new TypeError('Argument is not a string.')
throw new TypeError('Argument is not a string.')
}
// split the string by ':' character.
const [hour, minute, secondWithShift] = timeString.split(':')

View File

@ -19,3 +19,7 @@ test('The RailwayTimeConversion of 11:20:00PM is 23:20:00', () => {
const res = RailwayTimeConversion('11:20:00PM')
expect(res).toEqual('23:20:00')
})
test('The RailwayTimeConversion throws when input is not a string', () => {
expect(() => RailwayTimeConversion(1120)).toThrowError()
})