From 7ee7f122a871a8989ec8150f85cbd3c2dcfa3bce Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Mon, 9 Feb 2026 17:21:24 +0100 Subject: [PATCH] frontend-test-utils: adjust fetch mock + add createApiMock Signed-off-by: Patrik Oldsberg --- ...tend-test-utils-mock-apis-and-shorthand.md | 2 + .../utility-apis/05-testing.md | 41 +++- packages/frontend-test-utils/package.json | 1 - packages/frontend-test-utils/report.api.md | 180 +++--------------- .../src/apis/FetchApi/MockFetchApi.ts | 8 +- .../src/apis/createApiMock.test.ts | 86 +++++++++ .../src/apis/createApiMock.ts | 87 +++++++++ .../frontend-test-utils/src/apis/index.ts | 3 +- .../frontend-test-utils/src/apis/mockApis.ts | 70 ++----- yarn.lock | 1 - 10 files changed, 255 insertions(+), 224 deletions(-) create mode 100644 packages/frontend-test-utils/src/apis/createApiMock.test.ts create mode 100644 packages/frontend-test-utils/src/apis/createApiMock.ts diff --git a/.changeset/frontend-test-utils-mock-apis-and-shorthand.md b/.changeset/frontend-test-utils-mock-apis-and-shorthand.md index 546d2e102c..c864cba776 100644 --- a/.changeset/frontend-test-utils-mock-apis-and-shorthand.md +++ b/.changeset/frontend-test-utils-mock-apis-and-shorthand.md @@ -17,3 +17,5 @@ renderInTestApp(, { apis: [mockApis.identity()], }); ``` + +This change also adds `createApiMock`, a public utility for creating mock API factories, intended for plugin authors to create their own `.mock()` variants. diff --git a/docs/frontend-system/utility-apis/05-testing.md b/docs/frontend-system/utility-apis/05-testing.md index 522b7c2530..70b8ca70e9 100644 --- a/docs/frontend-system/utility-apis/05-testing.md +++ b/docs/frontend-system/utility-apis/05-testing.md @@ -124,28 +124,53 @@ renderTestApp({ }); ``` -### Creating your own mock APIs with `attachMockApiFactory` +### Creating your own mock APIs -If you maintain a plugin that exposes a utility API, you can use `attachMockApiFactory` to create mock instances that can be passed directly to test utilities: +If you maintain a plugin that exposes a utility API, you can provide mock utilities that follow the same function + `.mock()` pattern as the built-in `mockApis`. + +Use `attachMockApiFactory` for fake instances with real behavior, and `createApiMock` for the jest-mocked `.mock()` variant where all methods are `jest.fn()`. The full pattern looks like this: ```ts -import { attachMockApiFactory } from '@backstage/frontend-test-utils'; +import { + attachMockApiFactory, + createApiMock, + type ApiMock, +} from '@backstage/frontend-test-utils'; import { myApiRef, type MyApi } from '@internal/plugin-example-react'; +// Fake instance with real behavior export function myApiMock(options?: { greeting?: string }): MyApi { - const instance: MyApi = { + return attachMockApiFactory(myApiRef, { greet: async () => options?.greeting ?? 'Hello!', - }; - return attachMockApiFactory(myApiRef, instance); + }); +} + +// Jest mock variant where all methods are jest.fn() +export namespace myApiMock { + export const mock = createApiMock(myApiRef, () => ({ + greet: jest.fn(), + })); } ``` -Consumers can then use it like the built-in mocks: +Consumers can then use it just like the core mocks: ```tsx +// Fake with real behavior await renderInTestApp(, { apis: [myApiMock({ greeting: 'Hi there!' })], }); + +// Jest mock for assertions +const api = myApiMock.mock({ + greet: async () => 'mocked', +}); + +await renderInTestApp(, { + apis: [api], +}); + +expect(api.greet).toHaveBeenCalledTimes(1); ``` ## Available mock APIs @@ -160,7 +185,7 @@ The table below lists all core APIs available through the `mockApis` namespace. | `mockApis.discovery({ baseUrl })` | Inline | Returns `${baseUrl}/api/${pluginId}`, defaults to `http://example.com` | | `mockApis.error(options?)` | `MockErrorApi` | Collects errors; has `getErrors()`, `waitForError()` | | `mockApis.featureFlags(options?)` | `MockFeatureFlagsApi` | In-memory flag state; has `getState()`, `setState()`, `clearState()` | -| `mockApis.fetch(options?)` | `MockFetchApi` | Wraps `cross-fetch`; supports identity injection and plugin protocol | +| `mockApis.fetch(options?)` | `MockFetchApi` | Wraps native `fetch`; supports identity injection and plugin protocol | | `mockApis.identity(options?)` | Inline | Configurable user ref, ownership, token, profile | | `mockApis.permission(options?)` | `MockPermissionApi` | Defaults to `ALLOW`; accepts a handler function | | `mockApis.storage({ data })` | `MockStorageApi` | In-memory storage with bucket support | diff --git a/packages/frontend-test-utils/package.json b/packages/frontend-test-utils/package.json index e4e03602d2..028f9d1eff 100644 --- a/packages/frontend-test-utils/package.json +++ b/packages/frontend-test-utils/package.json @@ -43,7 +43,6 @@ "@backstage/test-utils": "workspace:^", "@backstage/types": "workspace:^", "@backstage/version-bridge": "workspace:^", - "cross-fetch": "^4.0.0", "i18next": "^22.4.15", "zen-observable": "^0.10.0", "zod": "^3.25.76" diff --git a/packages/frontend-test-utils/report.api.md b/packages/frontend-test-utils/report.api.md index c99007a6df..cbf48cbb17 100644 --- a/packages/frontend-test-utils/report.api.md +++ b/packages/frontend-test-utils/report.api.md @@ -15,7 +15,6 @@ import { AuthorizeResult } from '@backstage/plugin-permission-common'; import { Config } from '@backstage/config'; import { ConfigApi } from '@backstage/core-plugin-api'; import { ConfigApi as ConfigApi_2 } from '@backstage/frontend-plugin-api'; -import crossFetch from 'cross-fetch'; import { DiscoveryApi } from '@backstage/frontend-plugin-api'; import { DiscoveryApi as DiscoveryApi_2 } from '@backstage/core-plugin-api'; import { ErrorApi } from '@backstage/core-plugin-api'; @@ -55,7 +54,6 @@ import { withLogCollector } from '@backstage/test-utils'; // @public export type ApiMock = { - factory: ApiFactory; [mockApiFactorySymbol]: ApiFactory; } & { [Key in keyof TApi]: TApi[Key] extends (...args: infer Args) => infer Return @@ -71,6 +69,12 @@ export function attachMockApiFactory( [mockApiFactorySymbol]: ApiFactory; }; +// @public +export function createApiMock( + apiRef: ApiRef, + mockFactory: () => jest.Mocked, +): (partialImpl?: Partial) => ApiMock; + // @public (undocumented) export function createExtensionTester< T extends ExtensionDefinitionParameters, @@ -170,75 +174,23 @@ export namespace mockApis { export function alert(): MockWithApiFactory; export namespace alert { const mock: ( - partialImpl?: - | Partial<{ - post: jest.Mock; - alert$: jest.Mock; - }> - | undefined, - ) => ApiMock<{ - post: jest.Mock; - alert$: jest.Mock; - }>; + partialImpl?: Partial | undefined, + ) => ApiMock; } export function analytics(): MockAnalyticsApi & MockWithApiFactory; export namespace analytics { const // (undocumented) mock: ( - partialImpl?: - | Partial<{ - captureEvent: jest.Mock; - }> - | undefined, - ) => ApiMock<{ - captureEvent: jest.Mock; - }>; + partialImpl?: Partial | undefined, + ) => ApiMock; } export function config(options?: { data?: JsonObject; }): MockConfigApi & MockWithApiFactory; export namespace config { const // (undocumented) - mock: ( - partialImpl?: - | Partial<{ - has: jest.Mock; - keys: jest.Mock; - get: jest.Mock; - getOptional: jest.Mock; - getConfig: jest.Mock; - getOptionalConfig: jest.Mock; - getConfigArray: jest.Mock; - getOptionalConfigArray: jest.Mock; - getNumber: jest.Mock; - getOptionalNumber: jest.Mock; - getBoolean: jest.Mock; - getOptionalBoolean: jest.Mock; - getString: jest.Mock; - getOptionalString: jest.Mock; - getStringArray: jest.Mock; - getOptionalStringArray: jest.Mock; - }> - | undefined, - ) => ApiMock<{ - has: jest.Mock; - keys: jest.Mock; - get: jest.Mock; - getOptional: jest.Mock; - getConfig: jest.Mock; - getOptionalConfig: jest.Mock; - getConfigArray: jest.Mock; - getOptionalConfigArray: jest.Mock; - getNumber: jest.Mock; - getOptionalNumber: jest.Mock; - getBoolean: jest.Mock; - getOptionalBoolean: jest.Mock; - getString: jest.Mock; - getOptionalString: jest.Mock; - getStringArray: jest.Mock; - getOptionalStringArray: jest.Mock; - }>; + mock: (partialImpl?: Partial | undefined) => ApiMock; } export function discovery(options?: { baseUrl?: string; @@ -246,14 +198,8 @@ export namespace mockApis { export namespace discovery { const // (undocumented) mock: ( - partialImpl?: - | Partial<{ - getBaseUrl: jest.Mock; - }> - | undefined, - ) => ApiMock<{ - getBaseUrl: jest.Mock; - }>; + partialImpl?: Partial | undefined, + ) => ApiMock; } export function error( options?: MockErrorApiOptions, @@ -261,36 +207,16 @@ export namespace mockApis { export namespace error { const // (undocumented) mock: ( - partialImpl?: - | Partial<{ - post: jest.Mock; - error$: jest.Mock; - }> - | undefined, - ) => ApiMock<{ - post: jest.Mock; - error$: jest.Mock; - }>; + partialImpl?: Partial | undefined, + ) => ApiMock; } export function featureFlags( options?: MockFeatureFlagsApiOptions, ): MockWithApiFactory; export namespace featureFlags { const mock: ( - partialImpl?: - | Partial<{ - registerFlag: jest.Mock; - getRegisteredFlags: jest.Mock; - isActive: jest.Mock; - save: jest.Mock; - }> - | undefined, - ) => ApiMock<{ - registerFlag: jest.Mock; - getRegisteredFlags: jest.Mock; - isActive: jest.Mock; - save: jest.Mock; - }>; + partialImpl?: Partial | undefined, + ) => ApiMock; } export function fetch( options?: MockFetchApiOptions, @@ -298,14 +224,8 @@ export namespace mockApis { export namespace fetch { const // (undocumented) mock: ( - partialImpl?: - | Partial<{ - fetch: jest.Mock; - }> - | undefined, - ) => ApiMock<{ - fetch: jest.Mock; - }>; + partialImpl?: Partial | undefined, + ) => ApiMock; } export function identity(options?: { userEntityRef?: string; @@ -318,20 +238,8 @@ export namespace mockApis { export namespace identity { const // (undocumented) mock: ( - partialImpl?: - | Partial<{ - getBackstageIdentity: jest.Mock; - getCredentials: jest.Mock; - getProfileInfo: jest.Mock; - signOut: jest.Mock; - }> - | undefined, - ) => ApiMock<{ - getBackstageIdentity: jest.Mock; - getCredentials: jest.Mock; - getProfileInfo: jest.Mock; - signOut: jest.Mock; - }>; + partialImpl?: Partial | undefined, + ) => ApiMock; } export function permission(options?: { authorize?: @@ -344,14 +252,8 @@ export namespace mockApis { export namespace permission { const // (undocumented) mock: ( - partialImpl?: - | Partial<{ - authorize: jest.Mock; - }> - | undefined, - ) => ApiMock<{ - authorize: jest.Mock; - }>; + partialImpl?: Partial | undefined, + ) => ApiMock; } export function storage(options?: { data?: JsonObject; @@ -359,43 +261,21 @@ export namespace mockApis { export namespace storage { const // (undocumented) mock: ( - partialImpl?: - | Partial<{ - forBucket: jest.Mock; - snapshot: jest.Mock; - set: jest.Mock; - remove: jest.Mock; - observe$: jest.Mock; - }> - | undefined, - ) => ApiMock<{ - forBucket: jest.Mock; - snapshot: jest.Mock; - set: jest.Mock; - remove: jest.Mock; - observe$: jest.Mock; - }>; + partialImpl?: Partial | undefined, + ) => ApiMock; } export function translation(): MockTranslationApi & MockWithApiFactory; export namespace translation { const mock: ( - partialImpl?: - | Partial<{ - getTranslation: jest.Mock; - translation$: jest.Mock; - }> - | undefined, - ) => ApiMock<{ - getTranslation: jest.Mock; - translation$: jest.Mock; - }>; + partialImpl?: Partial | undefined, + ) => ApiMock; } } // @public export class MockConfigApi implements ConfigApi { - constructor(data: JsonObject); + constructor({ data }: { data: JsonObject }); get(key?: string): T; getBoolean(key: string): boolean; getConfig(key: string): Config; @@ -459,12 +339,12 @@ export interface MockFeatureFlagsApiOptions { // @public export class MockFetchApi implements FetchApi { constructor(options?: MockFetchApiOptions); - get fetch(): typeof crossFetch; + get fetch(): typeof fetch; } // @public export interface MockFetchApiOptions { - baseImplementation?: undefined | 'none' | typeof crossFetch; + baseImplementation?: undefined | 'none' | typeof fetch; injectIdentityAuth?: | undefined | { diff --git a/packages/frontend-test-utils/src/apis/FetchApi/MockFetchApi.ts b/packages/frontend-test-utils/src/apis/FetchApi/MockFetchApi.ts index 661d202379..b61ca680d1 100644 --- a/packages/frontend-test-utils/src/apis/FetchApi/MockFetchApi.ts +++ b/packages/frontend-test-utils/src/apis/FetchApi/MockFetchApi.ts @@ -24,8 +24,6 @@ import { FetchApi, IdentityApi, } from '@backstage/core-plugin-api'; -import crossFetch, { Response } from 'cross-fetch'; - /** * The options given when constructing a {@link MockFetchApi}. * @@ -47,7 +45,7 @@ export interface MockFetchApiOptions { * `jest.fn()`, if you want to use a custom implementation or to just track * and assert on calls. */ - baseImplementation?: undefined | 'none' | typeof crossFetch; + baseImplementation?: undefined | 'none' | typeof fetch; /** * Add translation from `plugin://` URLs to concrete http(s) URLs, basically @@ -103,7 +101,7 @@ export class MockFetchApi implements FetchApi { } /** {@inheritdoc @backstage/core-plugin-api#FetchApi.fetch} */ - get fetch(): typeof crossFetch { + get fetch(): typeof fetch { return this.implementation.fetch; } } @@ -124,7 +122,7 @@ function build(options?: MockFetchApiOptions): FetchApi { function baseImplementation( options: MockFetchApiOptions | undefined, -): typeof crossFetch { +): typeof fetch { const implementation = options?.baseImplementation; if (!implementation) { // Return a wrapper that evaluates global.fetch at call time, not construction time. diff --git a/packages/frontend-test-utils/src/apis/createApiMock.test.ts b/packages/frontend-test-utils/src/apis/createApiMock.test.ts new file mode 100644 index 0000000000..8b03b6df75 --- /dev/null +++ b/packages/frontend-test-utils/src/apis/createApiMock.test.ts @@ -0,0 +1,86 @@ +/* + * Copyright 2025 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { createApiRef } from '@backstage/frontend-plugin-api'; +import { createApiMock } from './createApiMock'; +import { getMockApiFactory } from './MockWithApiFactory'; + +describe('createApiMock', () => { + type TestApi = { + greet(name: string): string; + count: number; + }; + + const testApiRef = createApiRef({ id: 'test.create-mock' }); + + it('returns a factory function that produces jest mocks', () => { + const mock = createApiMock(testApiRef, () => ({ + greet: jest.fn(), + count: 0 as any, + })); + + const api = mock(); + api.greet('world'); + expect(api.greet).toHaveBeenCalledTimes(1); + expect(api.greet).toHaveBeenCalledWith('world'); + }); + + it('applies partial implementations via mockImplementation', () => { + const mock = createApiMock(testApiRef, () => ({ + greet: jest.fn(), + count: 0 as any, + })); + + const api = mock({ greet: (name: string) => `Hello ${name}!` }); + expect(api.greet('world')).toBe('Hello world!'); + expect(api.greet).toHaveBeenCalledTimes(1); + }); + + it('preserves non-function partial values', () => { + const mock = createApiMock(testApiRef, () => ({ + greet: jest.fn(), + count: 0 as any, + })); + + const api = mock({ count: 42 }); + expect(api.count).toBe(42); + }); + + it('attaches a mock API factory via the symbol', () => { + const mock = createApiMock(testApiRef, () => ({ + greet: jest.fn(), + count: 0 as any, + })); + + const api = mock(); + const factory = getMockApiFactory(api); + expect(factory).toBeDefined(); + expect(factory!.api).toBe(testApiRef); + }); + + it('creates fresh mocks on each call', () => { + const mock = createApiMock(testApiRef, () => ({ + greet: jest.fn(), + count: 0 as any, + })); + + const api1 = mock(); + const api2 = mock(); + api1.greet('a'); + expect(api1.greet).toHaveBeenCalledTimes(1); + expect(api2.greet).toHaveBeenCalledTimes(0); + }); +}); diff --git a/packages/frontend-test-utils/src/apis/createApiMock.ts b/packages/frontend-test-utils/src/apis/createApiMock.ts new file mode 100644 index 0000000000..759a8a1616 --- /dev/null +++ b/packages/frontend-test-utils/src/apis/createApiMock.ts @@ -0,0 +1,87 @@ +/* + * Copyright 2026 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ApiFactory, type ApiRef } from '@backstage/frontend-plugin-api'; +import { mockApiFactorySymbol } from './MockWithApiFactory'; + +/** + * Represents a mocked version of an API, where you automatically have access to + * the mocked versions of all of its methods along with a factory that returns + * that same mock. + * + * @public + */ +export type ApiMock = { + [mockApiFactorySymbol]: ApiFactory; +} & { + [Key in keyof TApi]: TApi[Key] extends (...args: infer Args) => infer Return + ? TApi[Key] & jest.MockInstance + : TApi[Key]; +}; + +/** + * Creates a standardized Backstage Utility API mockfactory function for + * producing mock API instances. + * + * @remarks + * + * 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. + * + * @public + * @example + * ```ts + * 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); + * ``` + */ +export function createApiMock( + apiRef: 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; + } + } + } + (mock as any)[mockApiFactorySymbol] = { + api: apiRef, + deps: {}, + factory: () => mock, + }; + return mock as unknown as ApiMock; + }; +} diff --git a/packages/frontend-test-utils/src/apis/index.ts b/packages/frontend-test-utils/src/apis/index.ts index 3bad319786..5be2398595 100644 --- a/packages/frontend-test-utils/src/apis/index.ts +++ b/packages/frontend-test-utils/src/apis/index.ts @@ -14,7 +14,8 @@ * limitations under the License. */ -export { type ApiMock, mockApis } from './mockApis'; +export { mockApis } from './mockApis'; +export { createApiMock, type ApiMock } from './createApiMock'; export { type MockApiFactorySymbol, type MockWithApiFactory, diff --git a/packages/frontend-test-utils/src/apis/mockApis.ts b/packages/frontend-test-utils/src/apis/mockApis.ts index 03d4ed32e0..efbc56bde8 100644 --- a/packages/frontend-test-utils/src/apis/mockApis.ts +++ b/packages/frontend-test-utils/src/apis/mockApis.ts @@ -18,7 +18,6 @@ import { alertApiRef, analyticsApiRef, configApiRef, - createApiFactory, discoveryApiRef, errorApiRef, fetchApiRef, @@ -34,7 +33,6 @@ import { type IdentityApi, type StorageApi, type TranslationApi, - ApiFactory, } from '@backstage/frontend-plugin-api'; import { permissionApiRef, @@ -59,53 +57,9 @@ import { MockPermissionApi } from './PermissionApi'; import { MockTranslationApi } from './TranslationApi'; import { mockWithApiFactory, - mockApiFactorySymbol, type MockWithApiFactory, } from './MockWithApiFactory'; - -/** - * Represents a mocked version of an API, where you automatically have access to - * the mocked versions of all of its methods along with a factory that returns - * that same mock. - * - * @public - */ -export type ApiMock = { - factory: ApiFactory; - [mockApiFactorySymbol]: ApiFactory; -} & { - [Key in keyof TApi]: TApi[Key] extends (...args: infer Args) => infer Return - ? TApi[Key] & jest.MockInstance - : TApi[Key]; -}; - -/** @internal */ -function simpleMock( - ref: any, - 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 apiMock = Object.assign(mock, { factory }) as ApiMock; - // Set the mock API symbol to the same factory - (apiMock as any)[mockApiFactorySymbol] = factory; - return apiMock; - }; -} +import { createApiMock } from './createApiMock'; /** * Mock implementations of the core utility APIs, to be used in tests. @@ -172,7 +126,7 @@ export namespace mockApis { * * @public */ - export const mock = simpleMock(alertApiRef, () => ({ + export const mock = createApiMock(alertApiRef, () => ({ post: jest.fn(), alert$: jest.fn(), })); @@ -215,7 +169,7 @@ export namespace mockApis { * * @public */ - export const mock = simpleMock(featureFlagsApiRef, () => ({ + export const mock = createApiMock(featureFlagsApiRef, () => ({ registerFlag: jest.fn(), getRegisteredFlags: jest.fn(), isActive: jest.fn(), @@ -241,7 +195,7 @@ export namespace mockApis { * @public */ export namespace analytics { - export const mock = simpleMock(analyticsApiRef, () => ({ + export const mock = createApiMock(analyticsApiRef, () => ({ captureEvent: jest.fn(), })); } @@ -273,7 +227,7 @@ export namespace mockApis { * * @public */ - export const mock = simpleMock(translationApiRef, () => ({ + export const mock = createApiMock(translationApiRef, () => ({ getTranslation: jest.fn(), translation$: jest.fn(), })); @@ -298,7 +252,7 @@ export namespace mockApis { * @public */ export namespace config { - export const mock = simpleMock(configApiRef, () => ({ + export const mock = createApiMock(configApiRef, () => ({ has: jest.fn(), keys: jest.fn(), get: jest.fn(), @@ -342,7 +296,7 @@ export namespace mockApis { * @public */ export namespace discovery { - export const mock = simpleMock(discoveryApiRef, () => ({ + export const mock = createApiMock(discoveryApiRef, () => ({ getBaseUrl: jest.fn(), })); } @@ -390,7 +344,7 @@ export namespace mockApis { * @public */ export namespace identity { - export const mock = simpleMock(identityApiRef, () => ({ + export const mock = createApiMock(identityApiRef, () => ({ getBackstageIdentity: jest.fn(), getCredentials: jest.fn(), getProfileInfo: jest.fn(), @@ -427,7 +381,7 @@ export namespace mockApis { * @public */ export namespace permission { - export const mock = simpleMock(permissionApiRef, () => ({ + export const mock = createApiMock(permissionApiRef, () => ({ authorize: jest.fn(), })); } @@ -451,7 +405,7 @@ export namespace mockApis { * @public */ export namespace storage { - export const mock = simpleMock(storageApiRef, () => ({ + export const mock = createApiMock(storageApiRef, () => ({ forBucket: jest.fn(), snapshot: jest.fn(), set: jest.fn(), @@ -479,7 +433,7 @@ export namespace mockApis { * @public */ export namespace error { - export const mock = simpleMock(errorApiRef, () => ({ + export const mock = createApiMock(errorApiRef, () => ({ post: jest.fn(), error$: jest.fn(), })); @@ -504,7 +458,7 @@ export namespace mockApis { * @public */ export namespace fetch { - export const mock = simpleMock(fetchApiRef, () => ({ + export const mock = createApiMock(fetchApiRef, () => ({ fetch: jest.fn(), })); } diff --git a/yarn.lock b/yarn.lock index a5ff49f678..9dfe77cd00 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3966,7 +3966,6 @@ __metadata: "@testing-library/jest-dom": "npm:^6.0.0" "@types/react": "npm:^18.0.0" "@types/zen-observable": "npm:^0.8.0" - cross-fetch: "npm:^4.0.0" i18next: "npm:^22.4.15" msw: "npm:^2.0.0" react: "npm:^18.0.2"