diff --git a/plugins/catalog-react/src/hooks/useEntityListProvider.test.tsx b/plugins/catalog-react/src/hooks/useEntityListProvider.test.tsx index cd92605875..ef3c83315a 100644 --- a/plugins/catalog-react/src/hooks/useEntityListProvider.test.tsx +++ b/plugins/catalog-react/src/hooks/useEntityListProvider.test.tsx @@ -40,7 +40,7 @@ import { EntityTypeFilter, EntityUserFilter, } from '../filters'; -import { MockPromise } from '../testUtils/MockPromise'; +import { createDeferred } from '@backstage/types'; import { EntityListPagination } from '../types'; import { EntityListProvider, useEntityList } from './useEntityListProvider'; @@ -349,8 +349,8 @@ describe('', () => { wrapper: createWrapper({ pagination }), }); - const firstResult = new MockPromise(); - const secondResult = new MockPromise(); + const firstResult = createDeferred(); + const secondResult = createDeferred(); await waitFor(() => { expect(result.current.backendEntities.length).toBeGreaterThan(0); diff --git a/plugins/catalog-react/src/testUtils/MockPromise.test.ts b/plugins/catalog-react/src/testUtils/MockPromise.test.ts deleted file mode 100644 index 6d6789f7a2..0000000000 --- a/plugins/catalog-react/src/testUtils/MockPromise.test.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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 { MockPromise } from './MockPromise.ts'; - -describe('MockPromise', () => { - it('is resolved when its resolve function is called', async () => { - const p = new MockPromise(); - p.resolve(12); - return expect(p).resolves.toBe(12); - }); - - it('is rejected when its reject function is called', async () => { - const p = new MockPromise(); - p.reject('Test rejection'); - return expect(p).rejects.toMatch('Test rejection'); - }); -}); diff --git a/plugins/catalog-react/src/testUtils/MockPromise.ts b/plugins/catalog-react/src/testUtils/MockPromise.ts deleted file mode 100644 index cc46eaafda..0000000000 --- a/plugins/catalog-react/src/testUtils/MockPromise.ts +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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. - */ -type ResolveFn = (value: T | PromiseLike) => void; -type RejectFn = (reason?: any) => void; -type Executor = (resolve: ResolveFn, reject: RejectFn) => void; - -export class MockPromise extends Promise { - private _resolve!: ResolveFn; - private _reject!: RejectFn; - - constructor(executor?: Executor) { - if (executor !== undefined) { - super(executor); - return; - } - - let res: ResolveFn; - let rej: RejectFn; - super((resolve, reject) => { - res = resolve; - rej = reject; - }); - this._resolve = res!; - this._reject = rej!; - } - - get resolve() { - return this._resolve; - } - - get reject() { - return this._reject; - } -}