Mirror: 馃帺 A tiny but capable push & pull stream library for TypeScript and Flow
at v6.3.2 2.1 kB view raw
1import { describe, it, expect, beforeEach, vi } from 'vitest'; 2 3import { Source } from '../types'; 4import { fromValue, makeSubject } from '../sources'; 5import { forEach } from '../sinks'; 6 7import { 8 passesPassivePull, 9 passesActivePush, 10 passesSinkClose, 11 passesSourceEnd, 12 passesSingleStart, 13 passesStrictEnd, 14} from './compliance'; 15 16import { combine, zip } from '../combine'; 17 18beforeEach(() => { 19 vi.useFakeTimers(); 20}); 21 22describe('zip', () => { 23 const noop = (source: Source<any>) => zip([fromValue(0), source]); 24 25 passesPassivePull(noop, [0, 0]); 26 passesActivePush(noop, [0, 0]); 27 passesSinkClose(noop); 28 passesSourceEnd(noop, [0, 0]); 29 passesSingleStart(noop); 30 passesStrictEnd(noop); 31 32 it('emits the zipped values of two sources', () => { 33 const { source: sourceA, next: nextA } = makeSubject<number>(); 34 const { source: sourceB, next: nextB } = makeSubject<number>(); 35 const fn = vi.fn(); 36 37 const combined = combine(sourceA, sourceB); 38 forEach(fn)(combined); 39 40 nextA(1); 41 expect(fn).not.toHaveBeenCalled(); 42 nextB(2); 43 expect(fn).toHaveBeenCalledWith([1, 2]); 44 }); 45 46 it('emits the zipped values of three sources', () => { 47 const { source: sourceA, next: nextA } = makeSubject<number>(); 48 const { source: sourceB, next: nextB } = makeSubject<number>(); 49 const { source: sourceC, next: nextC } = makeSubject<number>(); 50 const fn = vi.fn(); 51 52 const combined = zip([sourceA, sourceB, sourceC]); 53 forEach(fn)(combined); 54 55 nextA(1); 56 expect(fn).not.toHaveBeenCalled(); 57 nextB(2); 58 expect(fn).not.toHaveBeenCalled(); 59 nextC(3); 60 expect(fn).toHaveBeenCalledWith([1, 2, 3]); 61 }); 62 63 it('emits the zipped values of a dictionary of two sources', () => { 64 const { source: sourceA, next: nextA } = makeSubject<number>(); 65 const { source: sourceB, next: nextB } = makeSubject<number>(); 66 const fn = vi.fn(); 67 68 const combined = zip({ a: sourceA, b: sourceB }); 69 forEach(fn)(combined); 70 71 nextA(1); 72 expect(fn).not.toHaveBeenCalled(); 73 nextB(2); 74 expect(fn).toHaveBeenCalledWith({ a: 1, b: 2 }); 75 }); 76});