Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

String.test.ts

18 lines556 Bytes

1import { describe, expect, it } from "vite-plus/test";
2​
3import { truncate } from "./String.ts";
4​
5describe("truncate", () => {
6 it("cuts by Unicode code point so emoji stay whole", () => {
7 expect(truncate("πŸ‘πŸ‘πŸ‘", 5)).toBe("πŸ‘πŸ‘πŸ‘");
8 expect(truncate("πŸ‘πŸ‘πŸ‘πŸ‘", 3)).toBe("πŸ‘πŸ‘πŸ‘...");
9 });
10​
11 it("trims before measuring", () => {
12 expect(truncate(" hello ", 5)).toBe("hello");
13 });
14​
15 it("drops whitespace at the cut before the ellipsis", () => {
16 expect(truncate("hello world", 6)).toBe("hello...");
17 });
18});