Fix tests to wrap all calls changing the UI with act. (#12268)

This commit is contained in:
Jacob Richman
2025-10-30 11:50:26 -07:00
committed by GitHub
parent cc081337b7
commit 54fa26ef0e
69 changed files with 2002 additions and 1291 deletions

View File

@@ -5,7 +5,8 @@
*/
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { render } from 'ink-testing-library';
import { act } from 'react';
import { render } from '../../test-utils/render.js';
import type {
Config,
CodeAssistServer,
@@ -13,6 +14,7 @@ import type {
} from '@google/gemini-cli-core';
import { UserTierId, getCodeAssistServer } from '@google/gemini-cli-core';
import { usePrivacySettings } from './usePrivacySettings.js';
import { waitFor } from '../../test-utils/async.js';
// Mock the dependencies
vi.mock('@google/gemini-cli-core', async (importOriginal) => {
@@ -52,7 +54,7 @@ describe('usePrivacySettings', () => {
const { result } = renderPrivacySettingsHook();
await vi.waitFor(() => {
await waitFor(() => {
expect(result.current.privacyState.isLoading).toBe(false);
});
@@ -71,7 +73,7 @@ describe('usePrivacySettings', () => {
const { result } = renderPrivacySettingsHook();
await vi.waitFor(() => {
await waitFor(() => {
expect(result.current.privacyState.isLoading).toBe(false);
});
@@ -90,7 +92,7 @@ describe('usePrivacySettings', () => {
const { result } = renderPrivacySettingsHook();
await vi.waitFor(() => {
await waitFor(() => {
expect(result.current.privacyState.isLoading).toBe(false);
});
@@ -118,15 +120,17 @@ describe('usePrivacySettings', () => {
const { result } = renderPrivacySettingsHook();
// Wait for initial load
await vi.waitFor(() => {
await waitFor(() => {
expect(result.current.privacyState.isLoading).toBe(false);
});
// Update the setting
await result.current.updateDataCollectionOptIn(false);
await act(async () => {
await result.current.updateDataCollectionOptIn(false);
});
// Wait for update to complete
await vi.waitFor(() => {
await waitFor(() => {
expect(result.current.privacyState.dataCollectionOptIn).toBe(false);
});