src/utils/rxjs-operators.spec.ts
import {expect} from 'chai';
import {TestScheduler} from 'rxjs/testing';
import {bufferDebounce, bufferDuringTime} from './rxjs-operators';
describe('utils/rxjs-operators', () => {
let testScheduler: TestScheduler;
beforeEach(() => {
testScheduler = new TestScheduler((actual, expected) => {
expect(actual).to.deep.equal(expected);
});
});
describe('bufferDebounce', () => {
it('should buffer emissions until t seconds without a new emission', () => {
testScheduler.run(({cold, expectObservable}) => {
const source = 'ab---c---- ---------- d--------- ----|';
const output = '---------- -----x---- ---------- y---|';
expectObservable(cold(source).pipe(bufferDebounce(10))).toBe(output, {
x: ['a', 'b', 'c'],
y: ['d'],
z: [],
});
});
});
});
describe('bufferDuringTime', () => {
it('should buffer emissions in the next t seconds after first emission', () => {
testScheduler.run(({cold, expectObservable}) => {
const source = 'ab---c---- ---------- ---- d--------- ---|';
const output = '---------- x--------- ---- ---------- y--|';
expectObservable(cold(source).pipe(bufferDuringTime(10))).toBe(output, {
x: ['a', 'b', 'c'],
y: ['d'],
});
});
});
});
});