import { defineComponent } from "vue"; import { describe, test, expect } from "vite-plus/test"; import { renderToString, Box, Text, useInput, useExit, useFocus, useFocusManager, useStdin, useStdout, useStderr, } from "@vue-tui/runtime"; describe("renderToString", () => { test("renders component to string", () => { const App = defineComponent(() => () => ( Hello )); const output = renderToString(App, { columns: 40 }); expect(output).toContain("Hello"); }); test("defaults to 80 columns", () => { const App = defineComponent(() => { return () => test; }); const output = renderToString(App); expect(output).toBe("test"); }); test("rethrows component errors after cleanup", () => { const App = defineComponent(() => { throw new Error("boom"); }); expect(() => renderToString(App)).toThrow("boom"); }); test("renders nested layout", () => { const App = defineComponent(() => () => ( Line 1 Line 2 )); const output = renderToString(App, { columns: 20 }); expect(output).toContain("Line 1"); expect(output).toContain("Line 2"); }); test("useInput does not throw in renderToString", () => { const App = defineComponent(() => { useInput(() => {}); return () => with input; }); const output = renderToString(App); expect(output).toContain("with input"); }); test("useExit does not throw in renderToString", () => { const App = defineComponent(() => { const exit = useExit(); // exit is a function but calling it is a no-op void exit; return () => with exit; }); const output = renderToString(App); expect(output).toContain("with exit"); }); test("useFocus does not throw in renderToString", () => { const App = defineComponent(() => { const { isFocused } = useFocus(); return () => focused: {String(isFocused.value)}; }); const output = renderToString(App); expect(output).toContain("focused:"); }); test("useFocusManager does not throw in renderToString", () => { const App = defineComponent(() => { const fm = useFocusManager(); void fm; return () => with focus manager; }); const output = renderToString(App); expect(output).toContain("with focus manager"); }); test("useStdin does not throw in renderToString", () => { const App = defineComponent(() => { const stdin = useStdin(); void stdin; return () => with stdin; }); const output = renderToString(App); expect(output).toContain("with stdin"); }); test("useStdout does not throw in renderToString", () => { const App = defineComponent(() => { const stdout = useStdout(); void stdout; return () => with stdout; }); const output = renderToString(App); expect(output).toContain("with stdout"); }); test("useStderr does not throw in renderToString", () => { const App = defineComponent(() => { const stderr = useStderr(); void stderr; return () => with stderr; }); const output = renderToString(App); expect(output).toContain("with stderr"); }); test("respects custom columns width", () => { const App = defineComponent(() => () => ( full width )); const narrow = renderToString(App, { columns: 20 }); const wide = renderToString(App, { columns: 60 }); // Both should contain the text expect(narrow).toContain("full width"); expect(wide).toContain("full width"); }); test("renders padding correctly", () => { const App = defineComponent(() => () => ( padded )); const output = renderToString(App, { columns: 20 }); expect(output).toContain(" padded"); }); test("rethrows non-Error values as wrapped Error", () => { const App = defineComponent(() => { throw "string error"; }); expect(() => renderToString(App)).toThrow("string error"); }); });