Replace MockPromise with existing createDeferred
Signed-off-by: Jacob Raihle kdm951 <jacob.raihle@teliacompany.com>
This commit is contained in:
@@ -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('<EntityListProvider />', () => {
|
||||
wrapper: createWrapper({ pagination }),
|
||||
});
|
||||
|
||||
const firstResult = new MockPromise<GetEntitiesResponse>();
|
||||
const secondResult = new MockPromise<GetEntitiesResponse>();
|
||||
const firstResult = createDeferred<GetEntitiesResponse>();
|
||||
const secondResult = createDeferred<GetEntitiesResponse>();
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.backendEntities.length).toBeGreaterThan(0);
|
||||
|
||||
@@ -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<number>();
|
||||
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');
|
||||
});
|
||||
});
|
||||
@@ -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<T> = (value: T | PromiseLike<T>) => void;
|
||||
type RejectFn = (reason?: any) => void;
|
||||
type Executor<T> = (resolve: ResolveFn<T>, reject: RejectFn) => void;
|
||||
|
||||
export class MockPromise<T> extends Promise<T> {
|
||||
private _resolve!: ResolveFn<T>;
|
||||
private _reject!: RejectFn;
|
||||
|
||||
constructor(executor?: Executor<T>) {
|
||||
if (executor !== undefined) {
|
||||
super(executor);
|
||||
return;
|
||||
}
|
||||
|
||||
let res: ResolveFn<T>;
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user