TestApiProvider()
Home > @backstage/test-utils
> TestApiProvider
The TestApiProvider
is a Utility API context provider that is particularly well suited for development and test environments such as unit tests, storybooks, and isolated plugin development setups.
It lets you provide any number of API implementations, without necessarily having to fully implement each of the APIs.
Signature:
TestApiProvider: <T extends any[]>(props: TestApiProviderProps<T>) => React.JSX.Element
Parameters
Parameter |
Type |
Description |
---|---|---|
props |
React.JSX.Element
Remarks
todo: remove this remark tag and ship in the api-reference. There's some odd formatting going on when this is made into a markdown doc, that there's no line break between the emitted
for To the following
so what happens is that when parsing in docusaurus, it thinks that the code block is mdx rather than a code snippet. Just omitting this from the report for now until we can work out how to fix later. A migration fromApiRegistry
and ApiProvider
might look like this, from:
renderInTestApp(
<ApiProvider
apis={ApiRegistry.from([
[identityApiRef, mockIdentityApi as unknown as IdentityApi]
])}
>
...
</ApiProvider>
)
To the following:
renderInTestApp(
<TestApiProvider apis={[[identityApiRef, mockIdentityApi]]}>
...
</TestApiProvider>
)
Note that the cast to IdentityApi
is no longer needed as long as the mock API implements a subset of the IdentityApi
.