diff --git a/plugins/catalog-graph/src/components/CatalogGraphCard/CatalogGraphCard.test.tsx b/plugins/catalog-graph/src/components/CatalogGraphCard/CatalogGraphCard.test.tsx
index 9d4c01f84e..916653f600 100644
--- a/plugins/catalog-graph/src/components/CatalogGraphCard/CatalogGraphCard.test.tsx
+++ b/plugins/catalog-graph/src/components/CatalogGraphCard/CatalogGraphCard.test.tsx
@@ -22,6 +22,7 @@ import {
EntityProvider,
entityRouteRef,
} from '@backstage/plugin-catalog-react';
+import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
import {
MockAnalyticsApi,
renderInTestApp,
@@ -38,20 +39,7 @@ import Button from '@material-ui/core/Button';
describe('', () => {
let entity: Entity;
let wrapper: JSX.Element;
- const catalog = {
- getEntities: jest.fn(),
- getEntityByRef: jest.fn(),
- getEntitiesByRefs: jest.fn(),
- removeEntityByUid: jest.fn(),
- getLocationById: jest.fn(),
- getLocationByRef: jest.fn(),
- addLocation: jest.fn(),
- removeLocationById: jest.fn(),
- refreshEntity: jest.fn(),
- getEntityAncestors: jest.fn(),
- getEntityFacets: jest.fn(),
- validateEntity: jest.fn(),
- };
+ const catalog = catalogApiMock.mock();
let apis: TestApiRegistry;
beforeEach(() => {
diff --git a/plugins/catalog-graph/src/components/CatalogGraphPage/CatalogGraphPage.test.tsx b/plugins/catalog-graph/src/components/CatalogGraphPage/CatalogGraphPage.test.tsx
index e188dcc7ff..9a081747ad 100644
--- a/plugins/catalog-graph/src/components/CatalogGraphPage/CatalogGraphPage.test.tsx
+++ b/plugins/catalog-graph/src/components/CatalogGraphPage/CatalogGraphPage.test.tsx
@@ -14,9 +14,14 @@
* limitations under the License.
*/
-import { RELATION_HAS_PART, RELATION_PART_OF } from '@backstage/catalog-model';
+import {
+ Entity,
+ RELATION_HAS_PART,
+ RELATION_PART_OF,
+} from '@backstage/catalog-model';
import { analyticsApiRef } from '@backstage/core-plugin-api';
import { catalogApiRef, entityRouteRef } from '@backstage/plugin-catalog-react';
+import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
import {
MockAnalyticsApi,
renderInTestApp,
@@ -112,24 +117,11 @@ describe.skip('', () => {
},
],
};
- const allEntities: Record = {
+ const allEntities: Record = {
'b:d/c': entityC,
'b:d/e': entityE,
};
- const catalog = {
- getEntities: jest.fn(),
- getEntityByRef: jest.fn(),
- getEntitiesByRefs: jest.fn(),
- removeEntityByUid: jest.fn(),
- getLocationById: jest.fn(),
- getLocationByRef: jest.fn(),
- addLocation: jest.fn(),
- removeLocationById: jest.fn(),
- refreshEntity: jest.fn(),
- getEntityAncestors: jest.fn(),
- getEntityFacets: jest.fn(),
- validateEntity: jest.fn(),
- };
+ const catalog = catalogApiMock.mock();
beforeEach(() => {
wrapper = (
diff --git a/plugins/catalog-graph/src/components/CatalogGraphPage/SelectedKindsFilter.test.tsx b/plugins/catalog-graph/src/components/CatalogGraphPage/SelectedKindsFilter.test.tsx
index 511592af0c..33b6dfdb13 100644
--- a/plugins/catalog-graph/src/components/CatalogGraphPage/SelectedKindsFilter.test.tsx
+++ b/plugins/catalog-graph/src/components/CatalogGraphPage/SelectedKindsFilter.test.tsx
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-import { GetEntityFacetsResponse } from '@backstage/catalog-client';
import { ApiProvider } from '@backstage/core-app-api';
import { AlertApi, alertApiRef } from '@backstage/core-plugin-api';
import { catalogApiRef } from '@backstage/plugin-catalog-react';
@@ -23,8 +22,9 @@ import { waitFor, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { SelectedKindsFilter } from './SelectedKindsFilter';
+import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
-const catalogApi = {
+const catalogApi = catalogApiMock.mock({
getEntityFacets: jest.fn().mockResolvedValue({
facets: {
kind: [
@@ -34,8 +34,8 @@ const catalogApi = {
{ value: 'Resource', count: 1 },
],
},
- } as GetEntityFacetsResponse),
-};
+ }),
+});
const apis = TestApiRegistry.from(
[catalogApiRef, catalogApi],
[alertApiRef, {} as AlertApi],
diff --git a/plugins/catalog-graph/src/components/EntityRelationsGraph/EntityRelationsGraph.test.tsx b/plugins/catalog-graph/src/components/EntityRelationsGraph/EntityRelationsGraph.test.tsx
index 0ba9a3375a..48c7f28336 100644
--- a/plugins/catalog-graph/src/components/EntityRelationsGraph/EntityRelationsGraph.test.tsx
+++ b/plugins/catalog-graph/src/components/EntityRelationsGraph/EntityRelationsGraph.test.tsx
@@ -28,6 +28,7 @@ import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React, { FunctionComponent } from 'react';
import { EntityRelationsGraph } from './EntityRelationsGraph';
+import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
/*
The tests in this file have been disabled for the following error:
@@ -142,19 +143,7 @@ describe.skip('', () => {
],
},
};
- const catalog = {
- getEntities: jest.fn(),
- getEntityByRef: jest.fn(),
- removeEntityByUid: jest.fn(),
- getLocationById: jest.fn(),
- getLocationByRef: jest.fn(),
- addLocation: jest.fn(),
- removeLocationById: jest.fn(),
- refreshEntity: jest.fn(),
- getEntityAncestors: jest.fn(),
- getEntityFacets: jest.fn(),
- validateEntity: jest.fn(),
- };
+ const catalog = catalogApiMock.mock();
const CUSTOM_TEST_ID = 'custom-test-id';
beforeEach(() => {
diff --git a/plugins/catalog-graph/src/components/EntityRelationsGraph/useEntityStore.test.ts b/plugins/catalog-graph/src/components/EntityRelationsGraph/useEntityStore.test.ts
index 786c37ca7e..d13ae25abf 100644
--- a/plugins/catalog-graph/src/components/EntityRelationsGraph/useEntityStore.test.ts
+++ b/plugins/catalog-graph/src/components/EntityRelationsGraph/useEntityStore.test.ts
@@ -18,26 +18,14 @@ import { Entity } from '@backstage/catalog-model';
import { useApi as useApiMocked } from '@backstage/core-plugin-api';
import { act, renderHook, waitFor } from '@testing-library/react';
import { useEntityStore } from './useEntityStore';
+import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
jest.mock('@backstage/core-plugin-api');
const useApi = useApiMocked as jest.Mocked;
describe('useEntityStore', () => {
- const catalogApi = {
- getEntities: jest.fn(),
- getEntityByRef: jest.fn(),
- getEntitiesByRefs: jest.fn(),
- removeEntityByUid: jest.fn(),
- getLocationById: jest.fn(),
- getLocationByRef: jest.fn(),
- addLocation: jest.fn(),
- removeLocationById: jest.fn(),
- refreshEntity: jest.fn(),
- getEntityAncestors: jest.fn(),
- getEntityFacets: jest.fn(),
- validateEntity: jest.fn(),
- };
+ const catalogApi = catalogApiMock.mock();
beforeEach(() => {
useApi.mockReturnValue(catalogApi);
diff --git a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.test.tsx b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.test.tsx
index ec7762f50f..6e81b27c55 100644
--- a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.test.tsx
+++ b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.test.tsx
@@ -27,6 +27,7 @@ import {
generateEntities,
StepPrepareCreatePullRequest,
} from './StepPrepareCreatePullRequest';
+import { catalogApiMock } from '@backstage/plugin-catalog-react/testUtils';
describe('', () => {
const catalogImportApi: jest.Mocked = {
@@ -35,19 +36,7 @@ describe('', () => {
preparePullRequest: jest.fn(),
};
- const catalogApi = {
- getEntities: jest.fn(),
- addLocation: jest.fn(),
- getEntityByRef: jest.fn(),
- getLocationByRef: jest.fn(),
- getLocationById: jest.fn(),
- removeLocationById: jest.fn(),
- removeEntityByUid: jest.fn(),
- refreshEntity: jest.fn(),
- getEntityAncestors: jest.fn(),
- getEntityFacets: jest.fn(),
- validateEntity: jest.fn(),
- };
+ const catalogApi = catalogApiMock.mock();
const errorApi: jest.Mocked = {
error$: jest.fn(),
diff --git a/plugins/catalog-react/src/hooks/useRelatedEntities.test.tsx b/plugins/catalog-react/src/hooks/useRelatedEntities.test.tsx
index 092f8e164e..6dbbac44f5 100644
--- a/plugins/catalog-react/src/hooks/useRelatedEntities.test.tsx
+++ b/plugins/catalog-react/src/hooks/useRelatedEntities.test.tsx
@@ -20,6 +20,7 @@ import { renderHook, waitFor } from '@testing-library/react';
import React, { ComponentType, PropsWithChildren } from 'react';
import { catalogApiRef } from '../api';
import { useRelatedEntities } from './useRelatedEntities';
+import { catalogApiMock } from '../testUtils';
describe('useRelatedEntities', () => {
afterEach(() => {
@@ -46,9 +47,7 @@ describe('useRelatedEntities', () => {
],
};
- const catalogApi = {
- getEntitiesByRefs: jest.fn(),
- };
+ const catalogApi = catalogApiMock.mock();
const wrapper: ComponentType> = ({ children }) => {
return (
@@ -60,7 +59,7 @@ describe('useRelatedEntities', () => {
it('filters and requests entities', async () => {
catalogApi.getEntitiesByRefs.mockResolvedValueOnce({
- items: [entity, null], // one of them doesn't exist
+ items: [entity, undefined], // one of them doesn't exist
});
const rendered = renderHook(
diff --git a/plugins/home/src/homePageComponents/StarredEntities/Content.test.tsx b/plugins/home/src/homePageComponents/StarredEntities/Content.test.tsx
index dab67d0b76..ad26482961 100644
--- a/plugins/home/src/homePageComponents/StarredEntities/Content.test.tsx
+++ b/plugins/home/src/homePageComponents/StarredEntities/Content.test.tsx
@@ -84,11 +84,11 @@ describe('StarredEntitiesContent', () => {
it('should display call to action message if no entities are starred', async () => {
const mockedApi = new MockStarredEntitiesApi();
- const mockCatalogApi = {
+ const mockCatalogApi = catalogApiMock.mock({
getEntitiesByRefs: jest
.fn()
.mockImplementation(async () => ({ items: entities })),
- };
+ });
const { getByText } = await renderInTestApp(
{
it('should display user provided message if no entities are starred', async () => {
const mockedApi = new MockStarredEntitiesApi();
- const mockCatalogApi = {
+ const mockCatalogApi = catalogApiMock.mock({
getEntitiesByRefs: jest
.fn()
.mockImplementation(async () => ({ items: entities })),
- };
+ });
const { getByText } = await renderInTestApp(