test-utils: switch to new auto DI api

This commit is contained in:
Patrik Oldsberg
2020-09-04 17:33:55 +02:00
parent e7c04aedab
commit a5741ff0aa
5 changed files with 13 additions and 34 deletions
@@ -14,12 +14,7 @@
* limitations under the License.
*/
import {
ErrorApi,
ErrorContext,
errorApiRef,
Observable,
} from '@backstage/core-api';
import { ErrorApi, ErrorContext, Observable } from '@backstage/core-api';
type Options = {
collect?: boolean;
@@ -40,12 +35,6 @@ const nullObservable = {
};
export class MockErrorApi implements ErrorApi {
static factory = {
implements: errorApiRef,
deps: {},
factory: () => new MockErrorApi(),
};
private readonly errors = new Array<ErrorWithContext>();
private readonly waiters = new Set<Waiter>();
@@ -17,7 +17,6 @@
import {
Observable,
StorageApi,
storageApiRef,
StorageValueChange,
} from '@backstage/core-api';
import ObservableImpl from 'zen-observable';
@@ -25,12 +24,6 @@ import ObservableImpl from 'zen-observable';
export type MockStorageBucket = { [key: string]: any };
export class MockStorageApi implements StorageApi {
static factory = {
implements: storageApiRef,
deps: {},
factory: () => MockStorageApi.create(),
};
private readonly namespace: string;
private readonly data: MockStorageBucket;
@@ -49,9 +49,6 @@ describe('wrapInTestApp', () => {
expect.stringMatching(
/^Warning: An update to %s inside a test was not wrapped in act\(...\)/,
),
expect.stringMatching(
/^Warning: An update to %s inside a test was not wrapped in act\(...\)/,
),
]);
});
@@ -24,7 +24,7 @@ import privateExports, {
} from '@backstage/core-api';
import { RenderResult } from '@testing-library/react';
import { renderWithEffects } from '@backstage/test-utils-core';
import { createMockApiRegistry } from './mockApiRegistry';
import { mockApis } from './mockApis';
const { PrivateAppImpl } = privateExports;
@@ -58,10 +58,9 @@ export function wrapInTestApp(
options: TestAppOptions = {},
): ReactElement {
const { routeEntries = ['/'] } = options;
const apis = createMockApiRegistry();
const app = new PrivateAppImpl({
apis,
apis: [],
components: {
NotFoundErrorPage,
BootErrorPage,
@@ -80,6 +79,7 @@ export function wrapInTestApp(
variant: 'light',
},
],
defaultApis: mockApis,
});
let Wrapper: ComponentType;
@@ -14,14 +14,14 @@
* limitations under the License.
*/
import { ApiTestRegistry } from '@backstage/core-api';
import {
storageApiRef,
errorApiRef,
createApiFactory,
} from '@backstage/core-api';
import { MockErrorApi, MockStorageApi } from './apis';
export function createMockApiRegistry(): ApiTestRegistry {
const registry = new ApiTestRegistry();
registry.register(MockErrorApi.factory);
registry.register(MockStorageApi.factory);
return registry;
}
export const mockApis = [
createApiFactory(errorApiRef, new MockErrorApi()),
createApiFactory(storageApiRef, MockStorageApi.create()),
];