Skip to content

Commit

Permalink
test(groupBy): add test asserting lift is not broken
Browse files Browse the repository at this point in the history
Add test for groupBy() operator, to verify that it supports the composable lift architecture.

Test for issue #1085.
  • Loading branch information
staltz authored and benlesh committed Jan 27, 2016
1 parent 90df9e2 commit 9eb25ba
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions spec/operators/groupBy-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1346,4 +1346,45 @@ describe('Observable.prototype.groupBy()', function () {
expectObservable(source, unsub).toBe(expected, expectedGroups);
expectSubscriptions(e1.subscriptions).toBe(expectedSubs);
});

it('should not break lift() composability', function (done) {
function MyCustomObservable() {
Observable.apply(this, arguments);
}
MyCustomObservable.prototype = Object.create(Observable.prototype);
MyCustomObservable.prototype.constructor = MyCustomObservable;
MyCustomObservable.prototype.lift = function (operator) {
var obs = new MyCustomObservable();
obs.source = this;
obs.operator = operator;
return obs;
};

var result = new MyCustomObservable(function (observer) {
observer.next(1);
observer.next(2);
observer.next(3);
observer.complete();
}).groupBy(
function (x) { return x % 2; },
function (x) { return x + '!'; }
);

expect(result instanceof MyCustomObservable).toBe(true);

var expectedGroups = [
{ key: 1, values: ['1!', '3!'] },
{ key: 0, values: ['2!'] }
];

result
.subscribe(function (g) {
var expectedGroup = expectedGroups.shift();
expect(g.key).toBe(expectedGroup.key);

g.subscribe(function (x) {
expect(x).toBe(expectedGroup.values.shift());
});
}, done.fail, done);
});
});

0 comments on commit 9eb25ba

Please sign in to comment.