filter-async.spec.ts 1.1 KB

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