describe("Color", () => {
const prop = new p.Color(new SomeHasProps({a: {value: "#aabbccdd"}}), 'a')
it("should be an instance of Property", () => {
expect(prop).to.be.instanceof(p.Property)
})
describe("validate", () => {
const good_tuples = [
"rgb(255, 0, 0)",
"rgba(200, 0, 0, 0.5)",
"rgba(0, 255, 0, 0)",
"rgba(0, 0, 255, 1)",
]
const bad_tuples = [
"rgb(254.5, 0, 0)",
"rgba(245.5, 0, 0, 0.5)",
"rgba(255.0, 0, 0, 0.5)",
"rgba(2550, 0, 0, 0.5)",
"rgba(255, 0, 0, 5)",
"rgb(255, 0, 0, 0)",
"rgba(255, 0, 0, 0.5, 0)",
"rgb( )",
"rgb(a, b, c)",
]
it("should return undefined on RGBa input", () => {
expect(prop.validate("#aabbccdd")).to.be.undefined
})
describe("should return undefined on good integer rgb and rgba tuples", () => {
for (const good_tuple of good_tuples) {
it(`${good_tuple}`, () => {
expect(prop.validate(good_tuple)).to.be.undefined
})
}
})
describe("should throw Error on tuple with bad numerical values", () => {
for (const bad_tuple of bad_tuples) {
it(`${bad_tuple}`, () => {
function fn(): void {
prop.validate(bad_tuple)
}
expect(fn).to.throw(Error)
})
}
})
it("should return undefined on svg color input", () => {
for (const color in svg_colors)
expect(prop.validate(color)).to.be.undefined
})
it("should throw an Error on other input", () => {
validation_error(prop, true)
validation_error(prop, 10)
validation_error(prop, 10.2)
validation_error(prop, "foo")
validation_error(prop, {})
validation_error(prop, [])
validation_error(prop, null)
validation_error(prop, undefined)
})
})
})
请发表评论