filter-async.spec.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. import { filterAsync } from './filter-async';
  2. describe('filterAsync', () => {
  3. it('filters an array of promises', async () => {
  4. const a = Promise.resolve(true);
  5. const b = Promise.resolve(false);
  6. const c = Promise.resolve(true);
  7. const input = [a, b, c];
  8. const result = await filterAsync(input, item => item);
  9. expect(result).toEqual([a, c]);
  10. });
  11. it('filters a mixed array', async () => {
  12. const a = { value: Promise.resolve(true) };
  13. const b = { value: Promise.resolve(false) };
  14. const c = { value: true };
  15. const input = [a, b, c];
  16. const result = await filterAsync(input, item => item.value);
  17. expect(result).toEqual([a, c]);
  18. });
  19. it('filters a sync array', async () => {
  20. const a = { value: true };
  21. const b = { value: false };
  22. const c = { value: true };
  23. const input = [a, b, c];
  24. const result = await filterAsync(input, item => item.value);
  25. expect(result).toEqual([a, c]);
  26. });
  27. });