|
1 | 1 | import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; |
2 | | -import { getOutputOptions, outputItem, outputList } from "../lib/output.js"; |
| 2 | +import { |
| 3 | + formatError, |
| 4 | + getOutputOptions, |
| 5 | + outputItem, |
| 6 | + outputList, |
| 7 | +} from "../lib/output.js"; |
3 | 8 |
|
4 | 9 | describe("output", () => { |
5 | 10 | let logs: string[]; |
@@ -52,4 +57,37 @@ describe("output", () => { |
52 | 57 | }, |
53 | 58 | ); |
54 | 59 | }); |
| 60 | + |
| 61 | + describe("formatError", () => { |
| 62 | + it("formats error with code and message", () => { |
| 63 | + const result = formatError("TEST_ERROR", "Something went wrong"); |
| 64 | + expect(result).toContain("Error: TEST_ERROR"); |
| 65 | + expect(result).toContain("Something went wrong"); |
| 66 | + }); |
| 67 | + |
| 68 | + it("formats error with hints", () => { |
| 69 | + const result = formatError("TEST_ERROR", "Something went wrong", [ |
| 70 | + "Try this", |
| 71 | + "Or try that", |
| 72 | + ]); |
| 73 | + expect(result).toContain("Error: TEST_ERROR"); |
| 74 | + expect(result).toContain("Something went wrong"); |
| 75 | + expect(result).toContain(" - Try this"); |
| 76 | + expect(result).toContain(" - Or try that"); |
| 77 | + }); |
| 78 | + |
| 79 | + it("formats error with empty hints array", () => { |
| 80 | + const result = formatError("TEST_ERROR", "Something went wrong", []); |
| 81 | + expect(result).toContain("Error: TEST_ERROR"); |
| 82 | + expect(result).toContain("Something went wrong"); |
| 83 | + expect(result).not.toContain(" - "); |
| 84 | + }); |
| 85 | + |
| 86 | + it("formats error without hints", () => { |
| 87 | + const result = formatError("NO_HINTS", "No hints provided"); |
| 88 | + expect(result).toContain("Error: NO_HINTS"); |
| 89 | + expect(result).toContain("No hints provided"); |
| 90 | + expect(result).not.toContain(" - "); |
| 91 | + }); |
| 92 | + }); |
55 | 93 | }); |
0 commit comments