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. // true.
const hexColorRegex = /^([\da-f]{3}){1,2}$/i const hexColorRegex = /^([\da-f]{3}){1,2}$/i
function isHexColor(s = '') { function isHexColor(s = '') {
return hexColorRegex.test(s.toLowerCase()) return hexColorRegex.test(s)
} }
function normalizeColor(color) { function normalizeColor(color) {

View File

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