0.0.0-development • Published 5 months ago

expect-template v0.0.0-development

Weekly downloads
-
License
-
Repository
-
Last release
5 months ago

expect-template

Make assertions on template literals

Installation

npm install expect-template

Usage

Jest

In you test-setup-file add:

import "expect-template";

With @jest/globals

In you test-setup-file add:

import "expect-template/jest-globals";

With Vitest

In you test-setup-file add:

import "expect-template/vitest";

With another Jest-compatible expect

import * as matchers from "expect-template/matchers";
import { expect } from "my-test-runner/expect";

expect.extend(matchers);

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"),
  });
});

it("compares css templates", () => {
  expect("1px solid rgb(0, 0, 0)").toEqualTemplate(
    css`1px solid ${expect.toBeColor("black")}`,
  );
});
0.0.0-development

5 months ago

0.0.2

5 months ago

0.0.1

5 months ago