strom/tests/unbatch.spec.ts

27 lines
662 B
TypeScript
Raw Normal View History

2019-08-15 21:06:54 +00:00
import { Readable } from "stream";
import test from "ava";
import { expect } from "chai";
2019-08-16 13:02:54 +00:00
import { unbatch, batch } from "../src";
2019-08-15 21:06:54 +00:00
test.cb("unbatch() unbatches", t => {
t.plan(3);
const source = new Readable({ objectMode: true });
const expectedElements = ["a", "b", "c"];
let i = 0;
source
.pipe(batch(3))
.pipe(unbatch())
.on("data", (element: string) => {
expect(element).to.equal(expectedElements[i]);
t.pass();
i++;
})
.on("error", t.end)
.on("end", t.end);
source.push("a");
source.push("b");
source.push("c");
source.push(null);
});