Skip to content

Commit 951124f

Browse files
committed
test(build): add tests for extractText defensive handling
- Add tests for undefined input handling - Add tests for null input handling - Add tests for non-array input handling - Verify extractText safely returns empty string for invalid inputs Signed-off-by: leocavalcante <leo@cavalcante.dev>
1 parent bc32249 commit 951124f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/build.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,25 @@ describe("build", () => {
187187

188188
expect(result).toBe("Line 1\nLine 2\nLine 3\nNext part")
189189
})
190+
191+
test("returns empty string for undefined input", () => {
192+
const result = extractText(undefined)
193+
194+
expect(result).toBe("")
195+
})
196+
197+
test("returns empty string for null input", () => {
198+
const result = extractText(null)
199+
200+
expect(result).toBe("")
201+
})
202+
203+
test("returns empty string for non-array input", () => {
204+
// biome-ignore lint/suspicious/noExplicitAny: testing invalid input
205+
const result = extractText({ type: "text", text: "not an array" } as any)
206+
207+
expect(result).toBe("")
208+
})
190209
})
191210

192211
describe("handleEvent", () => {

0 commit comments

Comments
 (0)