Backstage
    Preparing search index...
    • The TestApiProvider is a Utility API context provider for standalone rendering scenarios where you're not using renderInTestApp or other test utilities.

      It lets you provide any number of API implementations, without necessarily having to fully implement each of the APIs.

      Type Parameters

      • const TApiPairs extends any[]

      Returns Element

      For most test scenarios, prefer using the apis option in renderInTestApp or createExtensionTester instead of wrapping components with TestApiProvider.

      import { render } from '\@testing-library/react';
      import { myCustomApiRef } from '../apis';
      import { TestApiProvider, mockApis } from '\@backstage/frontend-test-utils';

      // Mock custom APIs with tuple syntax
      const myCustomApiMock = { myMethod: jest.fn() };
      render(
      <TestApiProvider
      apis={[
      [myCustomApiRef, myCustomApiMock]
      ]}
      >
      <MyComponent />
      </TestApiProvider>
      );

      // Use with built-in mock APIs (no tuples needed)
      render(
      <TestApiProvider
      apis={[
      mockApis.identity({ userEntityRef: 'user:default/guest' }),
      mockApis.alert(),
      ]}
      >
      <MyComponent />
      </TestApiProvider>
      );