TypeError: s.toLowerCase is not a function (#2997)

* Update color.js

* fixup

* expand test

* expand test (again)
This commit is contained in:
Danial
2019-02-19 20:52:37 +13:00
committed by Pierre-Yves B
parent 0e56258ac0
commit c2c27ea795
2 changed files with 21 additions and 5 deletions

View File

@@ -34,7 +34,7 @@ Object.entries(aliases).forEach(([alias, original]) => {
// true.
const hexColorRegex = /^([\da-f]{3}){1,2}$/i
function isHexColor(s = '') {
return hexColorRegex.test(s.toLowerCase())
return hexColorRegex.test(s)
}
function normalizeColor(color) {

View File

@@ -5,7 +5,16 @@ const { isHexColor, normalizeColor, toSvgColor } = require('./color')
test(isHexColor, () => {
forCases([given('f00bae'), given('4c1'), given('ABC123')]).expect(true)
forCases([given('f00bar'), given(''), given(undefined)]).expect(false)
forCases([
given('f00bar'),
given(''),
given(undefined),
given(null),
given(true),
given([]),
given({}),
given(() => {}),
]).expect(false)
})
test(normalizeColor, () => {
@@ -17,9 +26,16 @@ test(normalizeColor, () => {
given('#ABC123').expect('#abc123')
given('papayawhip').expect('papayawhip')
given('purple').expect('purple')
forCases([given(''), given(undefined), given('not-a-color')]).expect(
undefined
)
forCases([
given(''),
given('not-a-color'),
given(undefined),
given(null),
given(true),
given([]),
given({}),
given(() => {}),
]).expect(undefined)
given('lightgray').expect('lightgrey')
given('informational').expect('blue')
})