Skip to content

Commit

Permalink
test: add mycolor test
Browse files Browse the repository at this point in the history
  • Loading branch information
wzc520pyfm committed Mar 26, 2024
1 parent 78472fc commit d50e2fe
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
import { expect, it, describe } from "vitest";
import {} from "../src";
// eslint-disable-next-line import/no-named-as-default
import mycolor from "../src";

describe("packageName", () => {
it.todo("pass", () => {
expect(true).toBe(true);
describe("mycolor", () => {
it("should get mycolor by default", async () => {
const mycolor = await import("../src");
expect(mycolor).toBeDefined();
});
it("should get mycolor by named", async () => {
const { mycolor } = await import("../src");
expect(mycolor).toBeDefined();
});
it("should get a new mycolor instance", () => {
const color1 = mycolor(255, 165, 0, 1);
const color2 = mycolor(color1);
expect(color1).not.toBe(color2);
});
it("input rgba params, should get a rgba array", () => {
expect(mycolor(255, 165, 0, 1).rgba()).toEqual([255, 165, 0, 1]);
});
it("input hex, should get a rgba array", () => {
expect(mycolor("#ff3").rgba()).toEqual([255, 255, 51, 1]);
expect(mycolor("#ff36").rgba()).toEqual([255, 255, 51, 0.4]);
expect(mycolor("#ff3399").rgba()).toEqual([255, 51, 153, 1]);
expect(mycolor("#ff339966").rgba()).toEqual([255, 51, 153, 0.4]);
// without #
expect(mycolor("ff3").rgba()).toEqual([255, 255, 51, 1]);
expect(mycolor("ff36").rgba()).toEqual([255, 255, 51, 0.4]);
expect(mycolor("ff3399").rgba()).toEqual([255, 51, 153, 1]);
expect(mycolor("ff339966").rgba()).toEqual([255, 51, 153, 0.4]);
});
});

0 comments on commit d50e2fe

Please sign in to comment.