CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
mockCommandContext.test.ts63 linesDownload Raw Back to test-utils
1/**2 * @license3 * Copyright 2025 Google LLC4 * SPDX-License-Identifier: Apache-2.05 */6 7import { vi, describe, it, expect } from 'vitest';8import { createMockCommandContext } from './mockCommandContext.js';9 10describe('createMockCommandContext', () => {11  it('should return a valid CommandContext object with default mocks', () => {12    const context = createMockCommandContext();13 14    // Just a few spot checks to ensure the structure is correct15    // and functions are mocks.16    expect(context).toBeDefined();17    expect(context.ui.addItem).toBeInstanceOf(Function);18    expect(vi.isMockFunction(context.ui.addItem)).toBe(true);19  });20 21  it('should apply top-level overrides correctly', () => {22    const mockClear = vi.fn();23    const overrides = {24      ui: {25        clear: mockClear,26      },27    };28 29    const context = createMockCommandContext(overrides);30 31    // Call the function to see if the override was used32    context.ui.clear();33 34    // Assert that our specific mock was called, not the default35    expect(mockClear).toHaveBeenCalled();36    // And that other defaults are still in place37    expect(vi.isMockFunction(context.ui.addItem)).toBe(true);38  });39 40  it('should apply deeply nested overrides correctly', () => {41    // This is the most important test for factory's logic.42    const mockConfig = {43      getProjectRoot: () => '/test/project',44      getModel: () => 'gemini-pro',45    };46 47    const overrides = {48      services: {49        config: mockConfig,50      },51    };52 53    const context = createMockCommandContext(overrides);54 55    expect(context.services.config).toBeDefined();56    expect(context.services.config?.getModel()).toBe('gemini-pro');57    expect(context.services.config?.getProjectRoot()).toBe('/test/project');58 59    // Verify a default property on the same nested object is still there60    expect(context.services.logger).toBeDefined();61  });62});63 
basant307/AI_Governance_Project · CoolFace