redioactive
Version:
Reactive streams for chaining overlapping promises.
47 lines (46 loc) • 1.97 kB
JavaScript
"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('Batching values in a stream', () => {
test('Batches 5 values into batch length 2', async () => {
await expect((0, redio_1.default)([1, 2, 3, 4, 5]).batch(2).toArray()).resolves.toEqual([[1, 2], [3, 4], [5]]);
});
test('Batches 6 values into batch length 2', async () => {
await expect((0, redio_1.default)([1, 2, 3, 4, 5, 6]).batch(2).toArray()).resolves.toEqual([
[],
[],
[]
]);
});
test('Works with an empty stream', async () => {
await expect((0, redio_1.default)([]).batch(2).toArray()).resolves.toEqual([]);
});
test('Batch size bigger than stream', async () => {
await expect((0, redio_1.default)([1, 2, 3]).batch(4).toArray()).resolves.toEqual([[1, 2, 3]]);
});
test('Batch size and stream size are the same', async () => {
await expect((0, redio_1.default)([1, 2, 3]).batch(3).toArray()).resolves.toEqual([[1, 2, 3]]);
});
test('Batch size is a promise', async () => {
await expect((0, redio_1.default)([1, 2, 3, 4, 5]).batch(Promise.resolve(2)).toArray()).resolves.toEqual([
[],
[],
[]
]);
});
test('Batches 5 values into batch length 1', async () => {
await expect((0, redio_1.default)([1, 2, 3, 4, 5]).batch(1).toArray()).resolves.toEqual([
[],
[],
[],
[],
[]
]);
});
test('Batch size 0 is an error', async () => {
await expect((0, redio_1.default)([1, 2, 3]).batch(0).toArray()).rejects.toThrowError(/Batch/);
});
});