view-transition-name
Version:
Generate css `view-transition-name`s
65 lines • 2.57 kB
JavaScript
import { describe, expect, it } from "vitest";
import { viewTransitionName, ViewTransitionNameError, ViewTransitionNameReservedKeywordError, } from "./index.js";
describe("basics", () => {
it("should create a custom ident from strings", () => {
const result = viewTransitionName("foo", "bar", "baz@");
expect(result).toMatchInlineSnapshot(`"foo_bar_baz\\40"`);
});
it("should create a custom ident from an array of strings", () => {
const result = viewTransitionName(["my", "custom", "ident"]);
expect(result).toMatchInlineSnapshot(`"my_custom_ident"`);
});
it("should create a custom ident from array of values", () => {
const result = viewTransitionName([
undefined,
null,
true,
false,
3,
{ test: "hi", oof: 0 },
]);
expect(result).toMatchInlineSnapshot(`"undefined_null_true_false_3_test"`);
});
it("should create a custom ident from an object with truthy values", () => {
const result = viewTransitionName({ my: true, custom: "1", ident: 3 });
expect(result).toMatchInlineSnapshot(`"custom_ident_my"`);
});
it("should create a custom ident from mixed arguments", () => {
const result = viewTransitionName("my", ["custom", "ident"], {
another: true,
});
expect(result).toMatchInlineSnapshot(`"my_custom_ident_another"`);
});
it("should create a custom ident from nested arrays", () => {
const result = viewTransitionName([
"my",
["custom", "ident", { another: false }],
]);
expect(result).toMatchInlineSnapshot(`"my_custom_ident"`);
});
it("should create a custom ident from an object with falsy values", () => {
const result = viewTransitionName([
"c",
{ my: false, custom: "", ident: null },
]);
expect(result).toMatchInlineSnapshot(`"c"`);
});
});
it("should throw an error for empty custom ident", () => {
expect(() => viewTransitionName()).toThrowError(ViewTransitionNameError);
});
describe("should throw an error for invalid names", () => {
const keywords = [
"unset",
"initial",
"inherit",
"revert",
"revert-layer",
"match-element",
"none",
];
it.each(keywords)("should throw an error for '%s'", (name) => {
expect(() => viewTransitionName(name)).toThrowError(ViewTransitionNameReservedKeywordError);
});
});
//# sourceMappingURL=index.test.js.map