mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import { promiseSome } from '../../../src/util/PromiseUtil';
|
|
|
|
describe('PromiseUtil', (): void => {
|
|
describe('#promiseSome', (): void => {
|
|
const resultTrue = Promise.resolve(true);
|
|
const resultFalse = Promise.resolve(false);
|
|
const resultError = Promise.reject(new Error('generic error'));
|
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
const resultInfinite = new Promise<boolean>((): void => {});
|
|
|
|
it('returns false if no promise is provided.', async(): Promise<void> => {
|
|
await expect(promiseSome([])).resolves.toBe(false);
|
|
});
|
|
|
|
it('returns false if no promise returns true.', async(): Promise<void> => {
|
|
await expect(promiseSome([ resultFalse, resultFalse, resultFalse ])).resolves.toBe(false);
|
|
});
|
|
|
|
it('returns true if at least a promise returns true.', async(): Promise<void> => {
|
|
await expect(promiseSome([ resultFalse, resultTrue, resultFalse ])).resolves.toBe(true);
|
|
});
|
|
|
|
it('does not propagate errors.', async(): Promise<void> => {
|
|
await expect(promiseSome([ resultError, resultFalse, resultFalse ])).resolves.toBe(false);
|
|
});
|
|
|
|
it('works with a combination of promises.', async(): Promise<void> => {
|
|
await expect(promiseSome([ resultError, resultTrue, resultInfinite ])).resolves.toBe(true);
|
|
});
|
|
});
|
|
});
|