0.4.1 • Published 9 months ago
expect-color v0.4.1
expect-color
Make assertions on normalized color
Installation
npm install expect-colorUsage
Jest
In you test-setup-file add:
import "expect-color";With @jest/globals
In you test-setup-file add:
import "expect-color/jest-globals";With Vitest
In you test-setup-file add:
import "expect-color/vitest";With another Jest-compatible expect
import * as matchers from "expect-color/matchers";
import { expect } from "my-test-runner/expect";
expect.extend(matchers);Standalone
import { assertSameColor } from "expect-color/assert";
assertSameColor("red", "red");Usage
it("compares colors", () => {
// Same color in same color space
expect("rgb(255, 0, 255)").toBeColor("fuchsia");
// Same color in different color space
expect("fuchsia").toEqualColor("hsl(300, 100%, 50%)");
expect({ borderColor: "rgb(255, 0, 255)" }).toEqual({
borderColor: expect.toBeColor("fuchsia"),
});
});