Skip to content

Commit

Permalink
chore(test): use test marbles for windowCount operator spec
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj authored and benlesh committed Sep 24, 2015
1 parent 58b91fb commit 84e3684
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions spec/operators/windowCount-spec.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
/* globals describe, it, expect */
/* globals describe, it, expect, expectObservable, hot */
var Rx = require('../../dist/cjs/Rx');
var Observable = Rx.Observable;

describe('Observable.prototype.windowCount', function () {
it('should emit windows at intervals', function (done) {
var expected = [
[0, 1],
[1, 2],
[2, 3],
[3]
];
Observable.range(0, 4)
.windowCount(2, 1)
.take(3)
.mergeMap(function (x) { return x.toArray(); })
.subscribe(function (w) {
expect(w).toEqual(expected.shift())
}, null, done);
}, 2000);

it('should emit buffers at buffersize of intervals if not specified', function (done) {
var expected = [
[0, 1],
[2, 3],
[4, 5]
];
Observable.range(0, 6)
.windowCount(2)
.mergeMap(function (x) { return x.toArray(); })
.subscribe(function (w) {
expect(w).toEqual(expected.shift())
}, null, done);
}, 2000);
function mergeMapfunction(x) {
return x.toArray();
}

it('should emit windows at intervals', function () {
var e1 = hot('--a--b--c--d--|');
var expected = '-----w--x--y--(z|)';

expectObservable(e1.windowCount(2,1).mergeMap(mergeMapfunction)).toBe(expected, { w: ['a', 'b'], x: ['b', 'c'], y: ['c', 'd'], z: ['d'] });
});

it('should emit buffers at buffersize of intervals if not specified', function () {
var e1 = hot('--a--b--c--d--e--f--|');
var expected = '-----x-----y-----z--|';

expectObservable(e1.windowCount(2).mergeMap(mergeMapfunction)).toBe(expected, { x: ['a', 'b'], y: ['c', 'd'], z: ['e', 'f']});
});

it('should raises error if source raises error', function() {
var e1 = hot('--a--b--c--d--e--f--#');
var expected = '--------w--x--y--z--#';

expectObservable(e1.windowCount(3,1).mergeMap(mergeMapfunction)).toBe(expected, { w: ['a', 'b', 'c'], x: ['b', 'c', 'd'], y: ['c', 'd', 'e'], z: ['d', 'e', 'f'] });
});
});

0 comments on commit 84e3684

Please sign in to comment.