Skip to content

Commit

Permalink
Merge branch 'master' into unused-type-param-ErrorObservable
Browse files Browse the repository at this point in the history
  • Loading branch information
Tetsuharu OHZEKI authored Oct 27, 2016
2 parents 62d0364 + 89612b2 commit 24b2bc0
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 337 deletions.
21 changes: 21 additions & 0 deletions spec/operators/bufferCount-spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as Rx from '../../dist/cjs/Rx';
import { expect } from 'chai';
declare const {hot, asDiagram, expectObservable, expectSubscriptions};

const Observable = Rx.Observable;
Expand Down Expand Up @@ -31,6 +32,26 @@ describe('Observable.prototype.bufferCount', () => {
expectObservable(e1.bufferCount(2)).toBe(expected, values);
});

it('should buffer properly (issue #2062)', () => {
const item$ = new Rx.Subject();
const results = [];
item$
.bufferCount(3, 1)
.subscribe(value => {
results.push(value);

if (value.join() === '1,2,3') {
item$.next(4);
}
});

item$.next(1);
item$.next(2);
item$.next(3);

expect(results).to.deep.equal([[1, 2, 3], [2, 3, 4]]);
});

it('should emit partial buffers if source completes before reaching specified buffer count', () => {
const e1 = hot('--a--b--c--d--|');
const expected = '--------------(x|)';
Expand Down
50 changes: 15 additions & 35 deletions spec/operators/distinct-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,46 +138,29 @@ describe('Observable.prototype.distinct', () => {
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

it('should emit once if comparer returns true always regardless of source emits', () => {
const e1 = hot('--a--b--c--d--e--f--|');
const e1subs = '^ !';
const expected = '--a-----------------|';

expectObservable((<any>e1).distinct(() => true)).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

it('should emit all if comparer returns false always regardless of source emits', () => {
const e1 = hot('--a--a--a--a--a--a--|');
it('should distinguish values by key', () => {
const values = {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6};
const e1 = hot('--a--b--c--d--e--f--|', values);
const e1subs = '^ !';
const expected = '--a--a--a--a--a--a--|';
const expected = '--a--b--c-----------|';
const selector = (value: number) => value % 3;

expectObservable((<any>e1).distinct(() => false)).toBe(expected);
expectObservable((<any>e1).distinct(selector)).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

it('should distinguish values by selector', () => {
const e1 = hot('--a--b--c--d--e--f--|', {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6});
const e1subs = '^ !';
const expected = '--a-----c-----e-----|';
const selector = (x: number, y: number) => y % 2 === 0;

expectObservable((<any>e1).distinct(selector)).toBe(expected, {a: 1, c: 3, e: 5});
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

it('should raises error when comparer throws', () => {
it('should raises error when selector throws', () => {
const e1 = hot('--a--b--c--d--e--f--|');
const e1subs = '^ ! ';
const expected = '--a--b--c--# ';
const selector = (x: string, y: string) => {
if (y === 'd') {
throw 'error';
const selector = (value: string) => {
if (value === 'd') {
throw new Error('d is for dumb');
}
return x === y;
return value;
};

expectObservable((<any>e1).distinct(selector)).toBe(expected);
expectObservable((<any>e1).distinct(selector)).toBe(expected, undefined, new Error('d is for dumb'));
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

Expand All @@ -187,9 +170,8 @@ describe('Observable.prototype.distinct', () => {
const e2 = hot('-----------x--------|');
const e2subs = '^ !';
const expected = '--a--b--------a--b--|';
const selector = (x: string, y: string) => x === y;

expectObservable((<any>e1).distinct(selector, e2)).toBe(expected);
expectObservable((<any>e1).distinct(null, e2)).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});
Expand All @@ -200,9 +182,8 @@ describe('Observable.prototype.distinct', () => {
const e2 = hot('-----------x-#');
const e2subs = '^ !';
const expected = '--a--b-------#';
const selector = (x: string, y: string) => x === y;

expectObservable((<any>e1).distinct(selector, e2)).toBe(expected);
expectObservable((<any>e1).distinct(null, e2)).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});
Expand All @@ -214,9 +195,8 @@ describe('Observable.prototype.distinct', () => {
const e2subs = '^ ! ';
const unsub = ' ! ';
const expected = '--a--b------';
const selector = (x: string, y: string) => x === y;

expectObservable((<any>e1).distinct(selector, e2), unsub).toBe(expected);
expectObservable((<any>e1).distinct(null, e2), unsub).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
expectSubscriptions(e2.subscriptions).toBe(e2subs);
});
Expand Down
226 changes: 0 additions & 226 deletions spec/operators/distinctKey-spec.ts

This file was deleted.

Loading

0 comments on commit 24b2bc0

Please sign in to comment.