Backstage
    Preparing search index...
    • Creates a standardized Backstage Utility API mockfactory function for producing mock API instances.

      Type Parameters

      • TApi

      Parameters

      Returns (partialImpl?: Partial<TApi>) => ApiMock<TApi>

      Each method in the mock factory is a jest.fn(), and you can optionally pass partial implementations when calling the returned function. No type parameters should be provided to this function, they will be inferred from the provided API reference.

      import { createApiMock } from '@backstage/frontend-test-utils';
      import { myApiRef } from '../apis';

      // Set up the mock factory
      const mock = createApiMock(myApiRef, () => ({
      greet: jest.fn(),
      }));

      // Create a mock with default behavior
      const api = mock();

      // Or with a partial implementation
      const api = mock({ greet: async () => 'Hello!' });
      expect(api.greet).toHaveBeenCalledTimes(1);