UNPKG

redioactive

Version:

Reactive streams for chaining overlapping promises.

41 lines (40 loc) 1.32 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const redio_1 = __importDefault(require("../redio")); describe('Doto side effect values', () => { test('Each is called the expected number of times', async () => { const dotoFn = jest.fn(); await (0, redio_1.default)([1, 2, 3]) .doto(dotoFn) .each(() => { /* void */ }) .toPromise(); expect(dotoFn).toHaveBeenCalledTimes(3); expect(dotoFn.mock.calls).toEqual([[1], [2], [3]]); }); test('Words with an empty stream', async () => { const dotoFn = jest.fn(); await (0, redio_1.default)([]) .doto(dotoFn) .each(() => { /* void */ }) .toPromise(); expect(dotoFn).not.toHaveBeenCalled(); }); test('Side effect example', async () => { await expect((0, redio_1.default)([[1], [2], [3]]) .doto((x) => { x.push(1); }) .toArray()).resolves.toEqual([ [1, 1], [2, 1], [3, 1] ]); }); });