redioactive
Version:
Reactive streams for chaining overlapping promises.
78 lines (77 loc) • 2.89 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const redio_1 = __importStar(require("../redio"));
describe('Consming stream values', () => {
test('Pass through a stream', async () => {
await expect((0, redio_1.default)([1, 2, 3])
.consume((_err, x, push, next) => {
push(x);
next();
})
.toArray()).resolves.toEqual([1, 2, 3]);
});
test('Works with an empty stream', async () => {
await expect((0, redio_1.default)([])
.consume((_err, x, push, next) => {
push(x);
next();
})
.toArray()).resolves.toEqual([]);
});
test('Can create an empty stream', async () => {
await expect((0, redio_1.default)([1, 2, 3])
.consume((_err, _x, push, next) => {
push(redio_1.end);
next();
})
.toArray()).resolves.toEqual([]);
});
test('Double up values', async () => {
await expect((0, redio_1.default)([1, 2, 3])
.consume((_err, x, push, next) => {
push(x);
push(x);
next();
})
.toArray()).resolves.toEqual([1, 1, 2, 2, 3, 3]);
});
test('Filter even values', async () => {
await expect((0, redio_1.default)([1, 2, 3, 4, 5, 6])
.consume((_err, x, push, next) => {
if ((0, redio_1.isEnd)(x)) {
push(redio_1.end);
}
else if (x !== null && x % 2 === 0) {
push(x);
}
next();
})
.toArray()).resolves.toEqual([2, 4, 6]);
});
test('Handle errors', async () => {
fail('Testing errors for consume not implemented');
});
});