fix: ensure truncated result stays within maxLength limit

This commit is contained in:
YeonGyu-Kim
2026-02-07 19:13:35 +09:00
parent a0201e17b9
commit f94ae2032c
2 changed files with 8 additions and 16 deletions
+7 -7
View File
@@ -21,9 +21,9 @@ describe("truncateDescription", () => {
const result = truncateDescription(description)
// then
expect(result.length).toBe(123) // 120 + "..."
expect(result.length).toBe(120) // 117 chars + "..."
expect(result).toEndWith("...")
expect(result).toBe(description.slice(0, 120) + "...")
expect(result).toBe(description.slice(0, 117) + "...")
})
it("respects custom max length parameter", () => {
@@ -35,9 +35,9 @@ describe("truncateDescription", () => {
const result = truncateDescription(description, maxLength)
// then
expect(result.length).toBe(53) // 50 + "..."
expect(result.length).toBe(50) // 47 chars + "..."
expect(result).toEndWith("...")
expect(result).toBe(description.slice(0, 50) + "...")
expect(result).toBe(description.slice(0, 47) + "...")
})
it("handles empty string", () => {
@@ -71,7 +71,7 @@ describe("truncateDescription", () => {
const result = truncateDescription(description)
// then
expect(result.length).toBe(123) // 120 + "..."
expect(result.length).toBe(120)
expect(result).toContain("First sentence. Second sentence.")
expect(result).toEndWith("...")
})
@@ -84,7 +84,7 @@ describe("truncateDescription", () => {
const result = truncateDescription(description)
// then
expect(result.length).toBe(123) // 120 + "..."
expect(result.length).toBe(120)
expect(result).toStartWith("Check out https://example.com")
expect(result).toEndWith("...")
})
@@ -97,7 +97,7 @@ describe("truncateDescription", () => {
const result = truncateDescription(description)
// then
expect(result.length).toBe(123) // 120 + "..."
expect(result.length).toBe(120)
expect(result).toStartWith("Version 1.2.3")
expect(result).toEndWith("...")
})