-
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.
fix(expand): fix expand operator to match Rx3
- adds virtual time tests for expand - refactors expand to be its own operator, reducing inheritence
- Loading branch information
Showing
2 changed files
with
112 additions
and
57 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,29 +1,57 @@ | ||
/* globals describe, it, expect, expectObservable, hot, cold */ | ||
var Rx = require('../../dist/cjs/Rx'); | ||
var Observable = Rx.Observable; | ||
|
||
describe('Observable.prototype.expand()', function () { | ||
it('should map and recursively flatten', function (done) { | ||
var expected = [1, 2, 3, 4, 5]; | ||
Observable.of(0).expand(function (x) { | ||
if (x > 4) { | ||
it('should map and recursively flatten', function() { | ||
var values = { | ||
a: 1, | ||
b: 1 + 1, // a + a, | ||
c: 2 + 2, // b + b, | ||
d: 4 + 4, // c + c, | ||
e: 8 + 8, // d + d | ||
} | ||
var e1 = hot('a', values); | ||
/* | ||
expectation explanation: (conjunction junction?) ... | ||
since `cold('---(z|)')` emits `x + x` and completes on frame 30 | ||
but the next "expanded" return value is synchronously subscribed to in | ||
that same frame, it stacks like so: | ||
a | ||
---(b|) | ||
---(c|) | ||
---(d|) | ||
---(e|) (...which flattens into:) | ||
a--b--c--d--(e|) | ||
*/ | ||
var expected = 'a--b--c--d--(e|)'; | ||
|
||
expectObservable(e1.expand(function(x) { | ||
if(x === 16) { | ||
return Observable.empty(); | ||
} | ||
return Observable.of(x + 1); | ||
}) | ||
.subscribe(function (x) { | ||
expect(x).toBe(expected.shift()); | ||
}, null, done); | ||
return cold('---(z|)', { z: x + x }); | ||
})).toBe(expected, values); | ||
}); | ||
it('should map and recursively flatten with ScalarObservables', function (done) { | ||
var expected = [1, 2, 3, 4, 5]; | ||
Observable.of(0).expand(function (x) { | ||
if (x > 4) { | ||
|
||
it('should map and recursively flatten with scalars', function() { | ||
var values = { | ||
a: 1, | ||
b: 1 + 1, // a + a, | ||
c: 2 + 2, // b + b, | ||
d: 4 + 4, // c + c, | ||
e: 8 + 8, // d + d | ||
} | ||
var e1 = hot('a', values); | ||
var expected = '(abcde|)'; | ||
|
||
expectObservable(e1.expand(function(x) { | ||
if(x === 16) { | ||
return Observable.empty(); | ||
} | ||
return Observable.of(x + 1); | ||
}) | ||
.subscribe(function (x) { | ||
expect(x).toBe(expected.shift()); | ||
}, null, done); | ||
return Observable.of(x + x); // scalar | ||
})).toBe(expected, values); | ||
}); | ||
}); |
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