mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 16:26:47 +08:00
fix: throw error instead of returning it (#1624)
This commit is contained in:
@ -12,7 +12,7 @@
|
||||
const checkFlatCase = (varname) => {
|
||||
// firstly, check that input is a string or not.
|
||||
if (typeof varname !== 'string') {
|
||||
return new TypeError('Argument is not a string.')
|
||||
throw new TypeError('Argument is not a string.')
|
||||
}
|
||||
|
||||
const pat = /^[a-z]*$/
|
||||
|
@ -10,7 +10,7 @@
|
||||
const CheckKebabCase = (varName) => {
|
||||
// firstly, check that input is a string or not.
|
||||
if (typeof varName !== 'string') {
|
||||
return new TypeError('Argument is not a string.')
|
||||
throw new TypeError('Argument is not a string.')
|
||||
}
|
||||
|
||||
const pat = /(\w+)-(\w)([\w-]*)/
|
||||
|
@ -10,7 +10,7 @@
|
||||
const CheckPascalCase = (VarName) => {
|
||||
// firstly, check that input is a string or not.
|
||||
if (typeof VarName !== 'string') {
|
||||
return new TypeError('Argument is not a string.')
|
||||
throw new TypeError('Argument is not a string.')
|
||||
}
|
||||
|
||||
const pat = /^[A-Z][A-Za-z]*$/
|
||||
|
@ -15,4 +15,8 @@ describe('checkCamelCase', () => {
|
||||
const result = checkCamelCase(value)
|
||||
expect(result).toBe(false)
|
||||
})
|
||||
|
||||
it('should throw when input is not a string', () => {
|
||||
expect(() => checkCamelCase(100)).toThrowError()
|
||||
})
|
||||
})
|
||||
|
@ -15,4 +15,8 @@ describe('checkFlatCase function', () => {
|
||||
const actual = checkFlatCase('abcdefghijklmnopqrstuvwxyz')
|
||||
expect(actual).toBe(true)
|
||||
})
|
||||
|
||||
it('should throw when input is not a string', () => {
|
||||
expect(() => checkFlatCase(100)).toThrowError()
|
||||
})
|
||||
})
|
||||
|
@ -11,3 +11,7 @@ test('CheckKebabCase(The Algorithms) -> false', () => {
|
||||
const res = CheckKebabCase(word)
|
||||
expect(res).toBeFalsy()
|
||||
})
|
||||
|
||||
test('CheckKebabCase throws when input is not a string', () => {
|
||||
expect(() => CheckKebabCase(100)).toThrowError()
|
||||
})
|
||||
|
@ -17,3 +17,7 @@ test('CheckPascalCase(The Algorithms) -> false', () => {
|
||||
const res = CheckPascalCase(word)
|
||||
expect(res).toBeFalsy()
|
||||
})
|
||||
|
||||
test('CheckPascalCase throws when input is not a string', () => {
|
||||
expect(() => CheckPascalCase(100)).toThrowError()
|
||||
})
|
||||
|
Reference in New Issue
Block a user