fix: fix an error when the validLowerCase and validUpperCase function have no params

This commit is contained in:
Aisen60 2020-09-18 13:08:15 +08:00
parent 1bc2e5c198
commit 3e4fbb1b0c
2 changed files with 4 additions and 0 deletions

View File

@ -33,6 +33,7 @@ export function validURL(url) {
* @returns {Boolean} * @returns {Boolean}
*/ */
export function validLowerCase(str) { export function validLowerCase(str) {
if (str === undefined || str === null) return false
const reg = /^[a-z]+$/ const reg = /^[a-z]+$/
return reg.test(str) return reg.test(str)
} }
@ -42,6 +43,7 @@ export function validLowerCase(str) {
* @returns {Boolean} * @returns {Boolean}
*/ */
export function validUpperCase(str) { export function validUpperCase(str) {
if (str === undefined || str === null) return false
const reg = /^[A-Z]+$/ const reg = /^[A-Z]+$/
return reg.test(str) return reg.test(str)
} }

View File

@ -14,11 +14,13 @@ describe('Utils:validate', () => {
expect(validLowerCase('abc')).toBe(true) expect(validLowerCase('abc')).toBe(true)
expect(validLowerCase('Abc')).toBe(false) expect(validLowerCase('Abc')).toBe(false)
expect(validLowerCase('123abc')).toBe(false) expect(validLowerCase('123abc')).toBe(false)
expect(validLowerCase()).toBe(false)
}) })
it('validUpperCase', () => { it('validUpperCase', () => {
expect(validUpperCase('ABC')).toBe(true) expect(validUpperCase('ABC')).toBe(true)
expect(validUpperCase('Abc')).toBe(false) expect(validUpperCase('Abc')).toBe(false)
expect(validUpperCase('123ABC')).toBe(false) expect(validUpperCase('123ABC')).toBe(false)
expect(validUpperCase()).toBe(false)
}) })
it('validAlphabets', () => { it('validAlphabets', () => {
expect(validAlphabets('ABC')).toBe(true) expect(validAlphabets('ABC')).toBe(true)