Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtextrem authored and mergatron[bot] committed Jul 4, 2024
1 parent 33c0f92 commit 6f597e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ describe("hex()", () => {
expect(hex.test("#F000AA00")).toEqual(true)
expect(hex.test("#f00 0px")).toEqual(false)
expect(hex.test(red)).toEqual(false)
expect(hex.test(null)).toEqual(false)
expect(hex.test(undefined)).toEqual(false)
})

it("should split a hex value into the correct params", () => {
Expand All @@ -210,6 +212,8 @@ describe("rgba()", () => {
expect(rgba.test("rgba(255, 0, 0, 0.5) 0px")).toEqual(false)
expect(rgba.test({ red: 255 })).toEqual(true)
expect(rgba.test({ hue: 255 })).toEqual(false)
expect(rgba.test(null)).toEqual(false)
expect(rgba.test(undefined)).toEqual(false)
})

it("should split an rgba value into the correct params", () => {
Expand Down Expand Up @@ -248,6 +252,8 @@ describe("hsla()", () => {
expect(hsla.test("hsla(170 50% 45%/1)")).toEqual(true)
expect(hsla.test("hsla(177 37.4978% 76.66804% / 1)")).toEqual(true)
expect(hsla.test("hsla(170, 50%, 45%, 1) 0px")).toEqual(false)
expect(hsla.test(null)).toEqual(false)
expect(hsla.test(undefined)).toEqual(false)
})

it("should split an hsl value into the correct params", () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/framer-motion/src/value/types/color/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Color, HSLA, RGBA } from "../types"
import { floatRegex, isString, singleColorRegex } from "../utils"
import { floatRegex, isNullish, isString, singleColorRegex } from "../utils"

/**
* Returns true if the provided string is a color, ie rgba(0,0,0,0) or #000,
Expand All @@ -8,7 +8,9 @@ import { floatRegex, isString, singleColorRegex } from "../utils"
export const isColorString = (type: string, testProp?: string) => (v: any) => {
return Boolean(
(isString(v) && singleColorRegex.test(v) && v.startsWith(type)) ||
(testProp && !isNullish(v) && Object.prototype.hasOwnProperty.call(v, testProp))
(testProp &&
!isNullish(v) &&
Object.prototype.hasOwnProperty.call(v, testProp))
)
}

Expand Down

0 comments on commit 6f597e8

Please sign in to comment.