Skip to content
TypeScript
524 B
Raw Blame
import { describe, expect, it } from "vite-plus/test";

import { truncate } from "./String.ts";

describe("truncate", () => {
  it("leaves short text alone", () => {
    expect(truncate("hello", 50)).toBe("hello");
  });

  it("cuts by Unicode code point so emoji stay whole", () => {
    expect(truncate("πŸ‘πŸ‘πŸ‘", 5)).toBe("πŸ‘πŸ‘πŸ‘");
    expect(truncate("πŸ‘πŸ‘πŸ‘πŸ‘", 3)).toBe("πŸ‘πŸ‘πŸ‘...");
  });

  it("trims before measuring", () => {
    expect(truncate("  hello  ", 5)).toBe("hello");
  });
});