stack/packages/stack-shared/src/utils/strings.test.ts
CactusBlue 816d64c850
In-source unit tests (#429)
Co-authored-by: Konsti Wohlwend <n2d4xc@gmail.com>
2025-02-14 11:47:52 -08:00

34 lines
1.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { templateIdentity } from "./strings";
describe("templateIdentity", () => {
it("should be equivalent to a regular template string", () => {
const adjective = "scientific";
const noun = "railgun";
expect(templateIdentity`a certain scientific railgun`).toBe("a certain scientific railgun");
expect(templateIdentity`a certain ${adjective} railgun`).toBe(`a certain scientific railgun`);
expect(templateIdentity`a certain ${adjective} ${noun}`).toBe(`a certain scientific railgun`);
expect(templateIdentity`${adjective}${noun}`).toBe(`scientificrailgun`);
});
it("should work with empty strings", () => {
expect(templateIdentity``).toBe("");
expect(templateIdentity`${""}`).toBe("");
expect(templateIdentity`${""}${""}`).toBe("");
});
it("should work with normal arrays", () => {
expect(templateIdentity(
["a ", " scientific ", "gun"],
"certain", "rail")
).toBe("a certain scientific railgun");
expect(templateIdentity(["a"])).toBe("a");
});
it("should throw an error with wrong number of value arguments", () => {
expect(() => templateIdentity([])).toThrow();
expect(() => templateIdentity(["a", "b"])).toThrow();
expect(() => templateIdentity(["a", "b", "c"], "a", "b", "c")).toThrow();
});
});