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);
Creates a standardized Backstage Utility API mockfactory function for producing mock API instances.