Skip to content

Commit

Permalink
chore(test): update operator tests o-z to use pipeable operators (#3820)
Browse files Browse the repository at this point in the history
* refactor(observeOn-spec): update observeOn operator tests to use pipeable operators

* refactor(onErrorResumeNext-spec): update onErrorResumeNext operator tests to use pipeable operators

* refactor(pairwise-spec): update pairwise operator tests to use pipeable operators

* refactor(pluck-spec): update pluck operator tests to use pipeable operators

* refactor(publish-spec): update publish operator tests to use pipeable operators

* refactor(publishBehavior-spec): update publishBehavior operator tests to use pipeable operators

* refactor(publishLast-spec): update publishLast operator tests to use pipeable operators

* refactor(publishReplay-spec): update publishReplay operator tests to use pipeable operators

* refactor(reduce-spec): update reduce operator tests to use pipeable operators

* refactor(repeat-spec): update repeat operator tests to use pipeable operators

* refactor(repeatWhen-spec): update repeatWhen operator tests to use pipeable operators

* refactor(retry-spec): update retry operator tests to use pipeable operators

* refactor(retryWhen-spec): update retryWhen operator tests to use pipeable operators

* refactor(sample-spec): update sample operator tests to use pipeable operators

* refactor(sampleTime-spec): update sampleTime operator tests to use pipeable operators

* refactor(scan-spec): update scan operator tests to use pipeable operators

* refactor(sequenceEqual-spec): update sequenceEqual operator tests to use pipeable operators

* refactor(share-spec): update share operator tests to use pipeable operators

* refactor(shareReplay-spec): update shareReplay operator tests to use pipeable operators

* refactor(single-spec): update single operator tests to use pipeable operators

* refactor(skip-spec): update skip operator tests to use pipeable operators

* refactor(skipLast-spec): update skipLast operator tests to use pipeable operators

* refactor(skipWhile-spec): update skipWhile operator tests to use pipeable operators

* refactor(startWith-spec): update startWith operator tests to use pipeable operators

* refactor(subscribeOn-spec): update subscribeOn operator tests to use pipeable operators

* refactor(switchMap-spec): update switchMap operator tests to use pipeable operators

* refactor(switchMapTo-spec): update switchMapTo operator tests to use pipeable operators

* refactor(take-spec): update take operator tests to use pipeable operators

* refactor(takeLast-spec): update takeLast operator tests to use pipeable operators

* refactor(takeUntil-spec): update takeUntil operator tests to use pipeable operators

* refactor(takeWhile-spec): update takeWhile operator tests to use pipeable operators

* refactor(throttle-spec): update throttle operator tests to use pipeable operators

* refactor(throttleTime-spec): update throttleTime operator tests to use pipeable operators

* refactor(timeout-spec): update timeout operator tests to use pipeable operators

* refactor(timeoutWith-spec): update timeoutWith operator tests to use pipeable operators

* refactor(timestamp-spec): update timestamp operator tests to use pipeable operators

* refactor(toArray-spec): update toArray operator tests to use pipeable operators

* refactor(toPromise-spec): update toPromise Observable method tests to use pipeable operators and upd

* refactor(window-spec): update window operator tests to use pipeable operators

* refactor(windowCount-spec): update windowCount operator tests to use pipeable operators

* refactor(windowTime-spec): update windowTime operator tests to use pipeable operators

* refactor(windowWhen-spec): update windowWhen operator tests to use pipeable operators

* refactor(withLatestFrom-spec): update withLatestFrom operator tests to use pipeable operators

* refactor(zip-spec): update zip operator tests to use pipeable operators

* refactor(zipAll-spec): update zipAll operator tests to use pipeable operators

* refactor(timeInterval-spec): update timeInterval operator tests to use pipeable operators

* refactor(race-spec): update race operator tests to use pipeable operators
  • Loading branch information
natmegs authored and benlesh committed Jun 9, 2018
1 parent e3c2d5c commit 3b290ea
Show file tree
Hide file tree
Showing 47 changed files with 1,584 additions and 1,483 deletions.
34 changes: 18 additions & 16 deletions spec/operators/observeOn-spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import * as Rx from 'rxjs/Rx';
import { observeOn, mergeMap } from 'rxjs/operators';
import { TestScheduler } from 'rxjs/testing';
import { expect } from 'chai';
import { hot, expectObservable, expectSubscriptions } from '../helpers/marble-testing';
import { of, Observable, asapScheduler } from 'rxjs';

declare function asDiagram(arg: string): Function;

declare const rxTestScheduler: Rx.TestScheduler;
const Observable = Rx.Observable;
declare const rxTestScheduler: TestScheduler;

/** @test {observeOn} */
describe('Observable.prototype.observeOn', () => {
describe('observeOn operator', () => {
asDiagram('observeOn(scheduler)')('should observe on specified scheduler', () => {
const e1 = hot('--a--b--|');
const expected = '--a--b--|';
const sub = '^ !';

expectObservable(e1.observeOn(rxTestScheduler)).toBe(expected);
expectObservable(e1.pipe(observeOn(rxTestScheduler))).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(sub);
});

Expand All @@ -23,7 +24,7 @@ describe('Observable.prototype.observeOn', () => {
const expected = '-----a--b--|';
const sub = '^ !';

expectObservable(e1.observeOn(rxTestScheduler, 30)).toBe(expected);
expectObservable(e1.pipe(observeOn(rxTestScheduler, 30))).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(sub);
});

Expand All @@ -32,7 +33,7 @@ describe('Observable.prototype.observeOn', () => {
const expected = '--a--#';
const sub = '^ !';

expectObservable(e1.observeOn(rxTestScheduler)).toBe(expected);
expectObservable(e1.pipe(observeOn(rxTestScheduler))).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(sub);
});

Expand All @@ -41,7 +42,7 @@ describe('Observable.prototype.observeOn', () => {
const expected = '-----|';
const sub = '^ !';

expectObservable(e1.observeOn(rxTestScheduler)).toBe(expected);
expectObservable(e1.pipe(observeOn(rxTestScheduler))).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(sub);
});

Expand All @@ -50,7 +51,7 @@ describe('Observable.prototype.observeOn', () => {
const expected = '-----';
const sub = '^ ';

expectObservable(e1.observeOn(rxTestScheduler)).toBe(expected);
expectObservable(e1.pipe(observeOn(rxTestScheduler))).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(sub);
});

Expand All @@ -60,7 +61,7 @@ describe('Observable.prototype.observeOn', () => {
const expected = '--a-- ';
const unsub = ' ! ';

const result = e1.observeOn(rxTestScheduler);
const result = e1.pipe(observeOn(rxTestScheduler));

expectObservable(result, unsub).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(sub);
Expand All @@ -72,10 +73,11 @@ describe('Observable.prototype.observeOn', () => {
const expected = '--a-- ';
const unsub = ' ! ';

const result = e1
.mergeMap((x: string) => Observable.of(x))
.observeOn(rxTestScheduler)
.mergeMap((x: string) => Observable.of(x));
const result = e1.pipe(
mergeMap((x: string) => of(x)),
observeOn(rxTestScheduler),
mergeMap((x: string) => of(x))
);

expectObservable(result, unsub).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(sub);
Expand All @@ -89,7 +91,7 @@ describe('Observable.prototype.observeOn', () => {
// subscription structure, since we're going to hack in to analyze it in this test.
const subscription: any = new Observable<number>(observer => {
let i = 1;
return Rx.Scheduler.asap.schedule(function () {
return asapScheduler.schedule(function () {
if (i > 3) {
observer.complete();
} else {
Expand All @@ -98,7 +100,7 @@ describe('Observable.prototype.observeOn', () => {
}
});
})
.observeOn(Rx.Scheduler.asap)
.pipe(observeOn(asapScheduler))
.subscribe(
x => {
const observeOnSubscriber = subscription._subscriptions[0];
Expand Down
29 changes: 14 additions & 15 deletions spec/operators/onErrorResumeNext-spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { expect } from 'chai';
import * as Rx from 'rxjs/Rx';
import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing';
import { onErrorResumeNext } from 'rxjs/operators';
import { concat, throwError, of } from 'rxjs';

declare function asDiagram(arg: string): Function;

const Observable = Rx.Observable;

describe('Observable.prototype.onErrorResumeNext', () => {
describe('onErrorResumeNext operator', () => {
asDiagram('onErrorResumeNext')('should continue observable sequence with next observable', () => {
const source = hot('--a--b--#');
const next = cold( '--c--d--|');
const subs = '^ !';
const expected = '--a--b----c--d--|';

expectObservable(source.onErrorResumeNext(next)).toBe(expected);
expectObservable(source.pipe(onErrorResumeNext(next))).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
});

Expand All @@ -23,7 +22,7 @@ describe('Observable.prototype.onErrorResumeNext', () => {
const subs = '^ !';
const expected = '--a--b----c--d--|';

expectObservable(source.onErrorResumeNext(next)).toBe(expected);
expectObservable(source.pipe(onErrorResumeNext(next))).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
});

Expand All @@ -35,7 +34,7 @@ describe('Observable.prototype.onErrorResumeNext', () => {
const subs = '^ !';
const expected = '--a--b----c--d----e----f--g--|';

expectObservable(source.onErrorResumeNext(next)).toBe(expected);
expectObservable(source.pipe(onErrorResumeNext(next))).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
});

Expand All @@ -47,7 +46,7 @@ describe('Observable.prototype.onErrorResumeNext', () => {
const subs = '^ !';
const expected = '--a--b----c--d----e----f--g--|';

expectObservable(source.onErrorResumeNext(next1, next2, next3)).toBe(expected);
expectObservable(source.pipe(onErrorResumeNext(next1, next2, next3))).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
});

Expand All @@ -59,7 +58,7 @@ describe('Observable.prototype.onErrorResumeNext', () => {
const subs = '^ !';
const expected = '--a--b----c--d----e----f--g--|';

expectObservable(source.onErrorResumeNext(next1, next2, next3)).toBe(expected);
expectObservable(source.pipe(onErrorResumeNext(next1, next2, next3))).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
});

Expand All @@ -71,7 +70,7 @@ describe('Observable.prototype.onErrorResumeNext', () => {
const subs = '^ !';
const expected = '--c--d----e----f--g--|';

expectObservable(source.onErrorResumeNext(next1, next2, next3)).toBe(expected);
expectObservable(source.pipe(onErrorResumeNext(next1, next2, next3))).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
});

Expand All @@ -81,7 +80,7 @@ describe('Observable.prototype.onErrorResumeNext', () => {
const subs = '^ ';
const expected = '--a--b----';

expectObservable(source.onErrorResumeNext(next1)).toBe(expected);
expectObservable(source.pipe(onErrorResumeNext(next1))).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
});

Expand All @@ -91,7 +90,7 @@ describe('Observable.prototype.onErrorResumeNext', () => {
const subs = '^ ';
const expected = '-';

expectObservable(source.onErrorResumeNext(next1)).toBe(expected);
expectObservable(source.pipe(onErrorResumeNext(next1))).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
});

Expand All @@ -101,15 +100,15 @@ describe('Observable.prototype.onErrorResumeNext', () => {
const subs = '^ !';
const expected = '--a--b----c--d--|';

expectObservable(source.onErrorResumeNext(next)).toBe(expected);
expectObservable(source.pipe(onErrorResumeNext(next))).toBe(expected);
expectSubscriptions(source.subscriptions).toBe(subs);
});

it('should work with promise', (done: MochaDone) => {
const expected = [1, 2];
const source = Observable.concat(Observable.of(1), Observable.throw('meh'));
const source = concat(of(1), throwError('meh'));

source.onErrorResumeNext(Promise.resolve(2))
source.pipe(onErrorResumeNext(Promise.resolve(2)))
.subscribe(x => {
expect(expected.shift()).to.equal(x);
}, (err: any) => {
Expand Down
17 changes: 9 additions & 8 deletions spec/operators/pairwise-spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { hot, cold, expectObservable, expectSubscriptions } from '../helpers/marble-testing';
import { pairwise } from 'rxjs/operators';

declare function asDiagram(arg: string): Function;

/** @test {pairwise} */
describe('Observable.prototype.pairwise', () => {
describe('pairwise operator', () => {
asDiagram('pairwise')('should group consecutive emissions as arrays of two', () => {
const e1 = hot('--a--b-c----d--e---|');
const expected = '-----u-v----w--x---|';
Expand All @@ -15,7 +16,7 @@ describe('Observable.prototype.pairwise', () => {
x: ['d', 'e']
};

const source = (<any>e1).pairwise();
const source = (<any>e1).pipe(pairwise());

expectObservable(source).toBe(expected, values);
});
Expand All @@ -33,7 +34,7 @@ describe('Observable.prototype.pairwise', () => {
z: ['f', 'g']
};

const source = (<any>e1).pairwise();
const source = (<any>e1).pipe(pairwise());

expectObservable(source).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -47,7 +48,7 @@ describe('Observable.prototype.pairwise', () => {
const values = {
};

const source = (<any>e1).pairwise();
const source = (<any>e1).pipe(pairwise());

expectObservable(source).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -64,7 +65,7 @@ describe('Observable.prototype.pairwise', () => {
x: ['d', 'e']
};

const source = (<any>e1).pairwise();
const source = (<any>e1).pipe(pairwise());

expectObservable(source).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -75,7 +76,7 @@ describe('Observable.prototype.pairwise', () => {
const e1subs = '(^!)';
const expected = '|';

const source = (<any>e1).pairwise();
const source = (<any>e1).pipe(pairwise());

expectObservable(source).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -86,7 +87,7 @@ describe('Observable.prototype.pairwise', () => {
const e1subs = '^';
const expected = '-';

const source = (<any>e1).pairwise();
const source = (<any>e1).pipe(pairwise());

expectObservable(source).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -97,7 +98,7 @@ describe('Observable.prototype.pairwise', () => {
const e1subs = '(^!)';
const expected = '#';

const source = (<any>e1).pairwise();
const source = (<any>e1).pipe(pairwise());

expectObservable(source).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand Down
Loading

0 comments on commit 3b290ea

Please sign in to comment.