diff --git a/spec/operators/partition-spec.ts b/spec/operators/partition-spec.ts index 38be5734aa..140e7a503a 100644 --- a/spec/operators/partition-spec.ts +++ b/spec/operators/partition-spec.ts @@ -39,6 +39,20 @@ describe('Observable.prototype.partition', () => { expectSubscriptions(e1.subscriptions).toBe([e1subs, e1subs]); }); + it('should partition an observable into two using a predicate and thisArg', () => { + const e1 = hot('--a-b---a------d--a---c--|'); + const e1subs = '^ !'; + const expected = ['--a-----a---------a------|', + '----b----------d------c--|']; + + function predicate(x) { + return x === this.value; + } + + expectObservableArray(e1.partition(predicate, {value: 'a'}), expected); + expectSubscriptions(e1.subscriptions).toBe([e1subs, e1subs]); + }); + it('should pass errors to both returned observables', () => { const e1 = hot('--a-b---#'); const e1subs = '^ !'; @@ -225,4 +239,14 @@ describe('Observable.prototype.partition', () => { const e1 = hot('--a-b---a------d----'); expect(e1.partition).to.throw(); }); + + it('should accept thisArg', () => { + const thisArg = {}; + + Observable.of(1).partition(function (value: number) { + expect(this).to.deep.equal(thisArg); + return true; + }, thisArg) + .forEach((observable: Rx.Observable) => observable.subscribe()); + }); }); \ No newline at end of file diff --git a/src/operator/partition.ts b/src/operator/partition.ts index 3648cf6a03..c494190d6e 100644 --- a/src/operator/partition.ts +++ b/src/operator/partition.ts @@ -45,7 +45,7 @@ import { Observable } from '../Observable'; */ export function partition(this: Observable, predicate: (value: T) => boolean, thisArg?: any): [Observable, Observable] { return [ - filter.call(this, predicate), + filter.call(this, predicate, thisArg), filter.call(this, not(predicate, thisArg)) ]; }