From e6c336bc761dc659649bab6c5770af6d080d472c Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 9 Feb 2026 19:32:10 +0100 Subject: [PATCH] catalog-react: switch to createApiMock Signed-off-by: Patrik Oldsberg --- .../src/testUtils/catalogApiMock.ts | 36 ++----------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/plugins/catalog-react/src/testUtils/catalogApiMock.ts b/plugins/catalog-react/src/testUtils/catalogApiMock.ts index dd225adc54..007345de22 100644 --- a/plugins/catalog-react/src/testUtils/catalogApiMock.ts +++ b/plugins/catalog-react/src/testUtils/catalogApiMock.ts @@ -14,47 +14,17 @@ * limitations under the License. */ -import { - ApiFactory, - ApiRef, - createApiFactory, -} from '@backstage/frontend-plugin-api'; +import { ApiFactory, createApiFactory } from '@backstage/frontend-plugin-api'; import { InMemoryCatalogClient } from '@backstage/catalog-client/testUtils'; import { Entity } from '@backstage/catalog-model'; import { catalogApiRef } from '@backstage/plugin-catalog-react'; import { CatalogApi } from '@backstage/catalog-client'; import { - ApiMock, + createApiMock, attachMockApiFactory, type MockWithApiFactory, } from '@backstage/frontend-test-utils'; -/** @internal */ -function simpleMock( - ref: ApiRef, - mockFactory: () => jest.Mocked, -): (partialImpl?: Partial) => ApiMock { - return partialImpl => { - const mock = mockFactory(); - if (partialImpl) { - for (const [key, impl] of Object.entries(partialImpl)) { - if (typeof impl === 'function') { - (mock as any)[key].mockImplementation(impl); - } else { - (mock as any)[key] = impl; - } - } - } - const factory = createApiFactory({ - api: ref, - deps: {}, - factory: () => mock, - }); - const marked = attachMockApiFactory(ref, mock); - return Object.assign(marked, { factory }) as ApiMock; - }; -} - /** * Creates a fake catalog client that handles entities in memory storage. Note * that this client may be severely limited in functionality, and advanced @@ -92,7 +62,7 @@ export namespace catalogApiMock { * Creates a catalog client whose methods are mock functions, possibly with * some of them overloaded by the caller. */ - export const mock = simpleMock(catalogApiRef, () => ({ + export const mock = createApiMock(catalogApiRef, () => ({ getEntities: jest.fn(), getEntitiesByRefs: jest.fn(), queryEntities: jest.fn(),