redioactive
Version:
Reactive streams for chaining overlapping promises.
38 lines (37 loc) • 1.46 kB
JavaScript
;
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('Filtering values in a stream', () => {
test('Filters even values', async () => {
await expect((0, redio_1.default)([1, 2, 3, 4, 5, 6])
.filter((x) => x % 2 === 0)
.toArray()).resolves.toEqual([2, 4, 6]);
});
test('Matches everything', async () => {
await expect((0, redio_1.default)([1, 2, 3])
.filter(() => true)
.toArray()).resolves.toEqual([1, 2, 3]);
});
test('Matches nothing', async () => {
await expect((0, redio_1.default)([1, 2, 3])
.filter(() => false)
.toArray()).resolves.toEqual([]);
});
test('Works with an empty stream', async () => {
await expect((0, redio_1.default)([])
.filter((x) => x % 2 === 0)
.toArray()).resolves.toEqual([]);
});
test('Filters with promises', async () => {
await expect((0, redio_1.default)([1, 2, 3, 4, 5, 6])
.filter((x) => new Promise((resolve) => {
setTimeout(() => {
resolve(x % 2 === 0);
}, 5);
}))
.toArray()).resolves.toEqual([2, 4, 6]);
});
});