test: pin narrow-truncate re-measure parity with Ink

This commit is contained in:
Yunfei He
2026-05-28 16:36:30 +08:00
parent 4696b49313
commit 7b8ed05ef9
@@ -18,3 +18,22 @@ test("multi-line truncate text keeps its line count (height)", async () => {
expect(lines[0]).toBe("x");
expect(lines[1]).toBe("yhello");
});
// Narrow truncate: when the text exceeds the box width, Ink re-measures the
// wrapped text (so the node width shrinks to the truncated widest line) and
// then truncates again at paint, yielding a doubly-truncated result. Verified
// against real Ink (ink-testing-library): width=5 → ["x","…"]. This is
// intentional Ink parity — do NOT "fix" it to one-pass truncation (["x","yh…"]).
test("narrow truncate matches Ink's re-measure-then-truncate behavior", async () => {
const { lastFrame } = await render(
defineComponent(() => () => (
<Box width={5}>
<Text wrap="truncate">{"x\nyhello"}</Text>
</Box>
)),
{ columns: 100 },
);
const lines = stripAnsi(lastFrame()!).split("\n");
expect(lines[0]).toBe("x");
expect(lines[1]).toBe("…");
});