test(cli): refactor tests for async render utilities (#23252)

This commit is contained in:
Tommaso Sciortino
2026-03-20 20:08:29 +00:00
committed by GitHub
parent 86a3a913b5
commit 6c78eb7a39
198 changed files with 3592 additions and 4802 deletions
+10 -10
View File
@@ -61,15 +61,15 @@ describe('useBanner', () => {
mockedPersistentStateGet.mockReturnValue({});
});
it('should return warning text and warning color if warningText is present', () => {
it('should return warning text and warning color if warningText is present', async () => {
const data = { defaultText: 'Standard', warningText: 'Critical Error' };
const { result } = renderHook(() => useBanner(data));
const { result } = await renderHook(() => useBanner(data));
expect(result.current.bannerText).toBe('Critical Error');
});
it('should hide banner if show count exceeds max limit (Legacy format)', () => {
it('should hide banner if show count exceeds max limit (Legacy format)', async () => {
mockedPersistentStateGet.mockReturnValue({
[crypto
.createHash('sha256')
@@ -77,12 +77,12 @@ describe('useBanner', () => {
.digest('hex')]: 5,
});
const { result } = renderHook(() => useBanner(defaultBannerData));
const { result } = await renderHook(() => useBanner(defaultBannerData));
expect(result.current.bannerText).toBe('');
});
it('should increment the persistent count when banner is shown', () => {
it('should increment the persistent count when banner is shown', async () => {
const data = { defaultText: 'Tracker', warningText: '' };
// Current count is 1
@@ -90,7 +90,7 @@ describe('useBanner', () => {
[crypto.createHash('sha256').update(data.defaultText).digest('hex')]: 1,
});
renderHook(() => useBanner(data));
await renderHook(() => useBanner(data));
// Expect set to be called with incremented count
expect(mockedPersistentStateSet).toHaveBeenCalledWith(
@@ -101,19 +101,19 @@ describe('useBanner', () => {
);
});
it('should NOT increment count if warning text is shown instead', () => {
it('should NOT increment count if warning text is shown instead', async () => {
const data = { defaultText: 'Standard', warningText: 'Warning' };
renderHook(() => useBanner(data));
await renderHook(() => useBanner(data));
// Since warning text takes precedence, default banner logic (and increment) is skipped
expect(mockedPersistentStateSet).not.toHaveBeenCalled();
});
it('should handle newline replacements', () => {
it('should handle newline replacements', async () => {
const data = { defaultText: 'Line1\\nLine2', warningText: '' };
const { result } = renderHook(() => useBanner(data));
const { result } = await renderHook(() => useBanner(data));
expect(result.current.bannerText).toBe('Line1\nLine2');
});