fix(cli): prevent crash in AnsiOutputText when handling non-array data (#24498)

This commit is contained in:
Sehoon Shon
2026-04-02 07:48:17 -04:00
committed by GitHub
parent 242afd49a1
commit 44c8b43328
3 changed files with 44 additions and 7 deletions
@@ -156,4 +156,30 @@ describe('<AnsiOutputText />', () => {
expect(lastFrame()).toBeDefined();
unmount();
});
describe('robustness', () => {
it('does NOT crash when data is undefined', async () => {
const { lastFrame, unmount } = await render(
<AnsiOutputText
data={undefined as unknown as AnsiOutput}
width={80}
disableTruncation={true}
/>,
);
expect(lastFrame({ allowEmpty: true }).trim()).toBe('');
unmount();
});
it('does NOT crash when data is an object but not an array', async () => {
const { lastFrame, unmount } = await render(
<AnsiOutputText
data={{ summary: 'test' } as unknown as AnsiOutput}
width={80}
disableTruncation={true}
/>,
);
expect(lastFrame({ allowEmpty: true }).trim()).toBe('');
unmount();
});
});
});