diff --git a/.changeset/frontend-test-utils-mock-apis-and-shorthand.md b/.changeset/frontend-test-utils-mock-apis-and-shorthand.md index 945eaf75c1..546d2e102c 100644 --- a/.changeset/frontend-test-utils-mock-apis-and-shorthand.md +++ b/.changeset/frontend-test-utils-mock-apis-and-shorthand.md @@ -1,8 +1,8 @@ --- -'@backstage/frontend-test-utils': patch +'@backstage/frontend-test-utils': minor --- -Added a new `mockApis` namespace with mock implementations of many core APIs. Mock API instances can be passed directly to `TestApiProvider`, `renderInTestApp`, and `renderTestApp` without needing `[apiRef, impl]` tuples. +**BREAKING**: The `mockApis` namespace is no longer a re-export from `@backstage/test-utils`. It's now a standalone namespace with mock implementations of most core APIs. Mock API instances can be passed directly to `TestApiProvider`, `renderInTestApp`, and `renderTestApp` without needing `[apiRef, impl]` tuples. As part of this change, the `.factory()` method on some mocks has been removed, since it's now redundant. ```tsx // Before diff --git a/docs/frontend-system/utility-apis/05-testing.md b/docs/frontend-system/utility-apis/05-testing.md index f1a9110590..fc92eb2abb 100644 --- a/docs/frontend-system/utility-apis/05-testing.md +++ b/docs/frontend-system/utility-apis/05-testing.md @@ -9,7 +9,7 @@ When testing frontend components and extensions, you often need to provide mock ## The `mockApis` namespace -The `mockApis` namespace is the main entry point for creating mock utility API instances in tests. It provides three usage patterns for each API: +The `mockApis` namespace is the main entry point for creating mock utility API instances in tests. It provides two usage patterns for each API: ### Fake instances @@ -42,10 +42,6 @@ const catalogApi = mockApis.permission.mock({ expect(catalogApi.authorize).toHaveBeenCalledTimes(1); ``` -### API factories - -Call `.factory()` to get an `ApiFactory` suitable for more advanced wiring scenarios. - ## Providing mock APIs in tests ### With `renderInTestApp` diff --git a/packages/frontend-test-utils/report.api.md b/packages/frontend-test-utils/report.api.md index aa24db3a96..bef42bc9e0 100644 --- a/packages/frontend-test-utils/report.api.md +++ b/packages/frontend-test-utils/report.api.md @@ -171,7 +171,6 @@ export type MockApiFactorySymbol = typeof mockApiFactorySymbol; export namespace mockApis { export function alert(): MockWithApiFactory; export namespace alert { - const factory: () => any; const mock: ( partialImpl?: | Partial<{ @@ -279,7 +278,6 @@ export namespace mockApis { options?: MockFeatureFlagsApiOptions, ): MockWithApiFactory; export namespace featureFlags { - const factory: (options?: MockFeatureFlagsApiOptions | undefined) => any; const mock: ( partialImpl?: | Partial<{ diff --git a/packages/frontend-test-utils/src/apis/mockApis.ts b/packages/frontend-test-utils/src/apis/mockApis.ts index e6474dbe96..01def834e2 100644 --- a/packages/frontend-test-utils/src/apis/mockApis.ts +++ b/packages/frontend-test-utils/src/apis/mockApis.ts @@ -91,19 +91,6 @@ function simpleMock( }; } -/** @internal */ -function simpleFactory( - ref: any, - factory: (...args: TArgs) => TApi, -): (...args: TArgs) => any { - return (...args) => - createApiFactory({ - api: ref, - deps: {}, - factory: () => factory(...args), - }); -} - /** * Mock implementations of the core utility APIs, to be used in tests. * @@ -111,7 +98,7 @@ function simpleFactory( * @remarks * * There are some variations among the APIs depending on what needs tests - * might have, but overall there are three main usage patterns: + * might have, but overall there are two main usage patterns: * * 1: Creating an actual fake API instance, often with a simplified version * of functionality, by calling the mock API itself as a function. @@ -133,14 +120,6 @@ function simpleFactory( * expect(foo.someMethod).toHaveBeenCalledTimes(2); * expect(foo.otherMethod).toHaveBeenCalledWith(testData); * ``` - * - * 3: Creating an API factory that behaves similarly to the mock as per above. - * - * ```ts - * const factory = mockApis.foo.factory({ - * someMethod: () => 'mocked result', - * }); - * ``` */ export namespace mockApis { /** @@ -169,13 +148,6 @@ export namespace mockApis { * @public */ export namespace alert { - /** - * Creates a factory for a fake implementation of - * {@link @backstage/frontend-plugin-api#AlertApi}. - * - * @public - */ - export const factory = simpleFactory(alertApiRef, alert); /** * Creates a mock implementation of * {@link @backstage/frontend-plugin-api#AlertApi}. All methods are @@ -219,13 +191,6 @@ export namespace mockApis { * @public */ export namespace featureFlags { - /** - * Creates a factory for a fake implementation of - * {@link @backstage/frontend-plugin-api#FeatureFlagsApi}. - * - * @public - */ - export const factory = simpleFactory(featureFlagsApiRef, featureFlags); /** * Creates a mock implementation of * {@link @backstage/frontend-plugin-api#FeatureFlagsApi}. All methods are