-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(test): use test marbles for windowCount operator spec
- Loading branch information
Showing
1 changed file
with
25 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] }); | ||
}); | ||
}); |