UNPKG

redioactive

Version:

Reactive streams for chaining overlapping promises.

35 lines (34 loc) 1.77 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('Taking values from the start of the stream', () => { test('By default, takes a single value from the stream', async () => { await expect((0, redio_1.default)([1, 2, 3, 4]).take().toArray()).resolves.toEqual([1]); }); test('Take a single value from a stream', async () => { await expect((0, redio_1.default)([1, 2, 3, 4]).take(1).toArray()).resolves.toEqual([1]); }); test('Take two values from a stream', async () => { await expect((0, redio_1.default)([1, 2, 3, 4]).take(2).toArray()).resolves.toEqual([1, 2]); }); test('Copes with an empty stream', async () => { await expect((0, redio_1.default)([]).take(3).toArray()).resolves.toEqual([]); }); test('Takes more values than the stream length', async () => { await expect((0, redio_1.default)([1, 2, 3, 4]).take(10).toArray()).resolves.toEqual([1, 2, 3, 4]); }); test('Takes the same number as stream length', async () => { await expect((0, redio_1.default)([1, 2, 3, 4]).take(4).toArray()).resolves.toEqual([1, 2, 3, 4]); }); test('Drops two values by promise', async () => { await expect((0, redio_1.default)([1, 2, 3, 4]).take(Promise.resolve(2)).toArray()).resolves.toEqual([1, 2]); }); test('Can be chained', async () => { await expect((0, redio_1.default)([1, 2, 3, 4]).take(3).take(Promise.resolve(2)).toArray()).resolves.toEqual([ 1, 2 ]); }); });