Skip to content

Commit 69466c3

Browse files
committed
chore: format specs with prettier and remove pragma
1 parent d623dd9 commit 69466c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+809
-745
lines changed

.prettierrc.json

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@
44
"printWidth": 140,
55
"overrides": [
66
{
7-
"files": ["spec/**/*.ts", "spec-dtslint/**/*.ts"],
7+
"files": ["spec-dtslint/**/*.ts"],
88
"options": {
99
"requirePragma": true
1010
}
11-
},
12-
{
13-
"files": ["spec/operators/**/*.ts", "spec/subjects/**/*.ts"],
14-
"options": {
15-
"requirePragma": false
16-
}
1711
}
1812
]
1913
}

packages/rxjs/spec/Observable-spec.ts

+70-65
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { expect } from 'chai';
22
import * as sinon from 'sinon';
33
import { TeardownLogic } from '../src/internal/types';
44
import { Observable, config, Subscription, Subscriber, Operator, NEVER, Subject, of, throwError, EMPTY } from 'rxjs';
5-
import { map, filter, count, tap, combineLatestWith, concatWith, mergeWith, raceWith, zipWith, catchError, share} from 'rxjs/operators';
5+
import { map, filter, count, tap, combineLatestWith, concatWith, mergeWith, raceWith, zipWith, catchError, share } from 'rxjs/operators';
66
import { TestScheduler } from 'rxjs/testing';
77
import { observableMatcher } from './helpers/observableMatcher';
88
import { result } from 'lodash';
@@ -30,11 +30,12 @@ describe('Observable', () => {
3030
observer.complete();
3131
});
3232

33-
source.subscribe(
34-
{ next: function (x) {
33+
source.subscribe({
34+
next: function (x) {
3535
expect(x).to.equal(1);
36-
}, complete: done }
37-
);
36+
},
37+
complete: done,
38+
});
3839
});
3940

4041
it('should send errors thrown in the constructor down the error path', (done) => {
@@ -70,7 +71,7 @@ describe('Observable', () => {
7071
});
7172

7273
it('should reject promise when in error', (done) => {
73-
throwError(() => ('bad'))
74+
throwError(() => 'bad')
7475
.forEach(() => {
7576
done(new Error('should not be called'));
7677
})
@@ -178,13 +179,17 @@ describe('Observable', () => {
178179
const results: any[] = [];
179180
const next = function (value: string) {
180181
results.push(value);
181-
}
182-
next.bind = () => { /* lol */};
182+
};
183+
next.bind = () => {
184+
/* lol */
185+
};
183186

184187
const complete = function () {
185188
results.push('done');
186-
}
187-
complete.bind = () => { /* lol */};
189+
};
190+
complete.bind = () => {
191+
/* lol */
192+
};
188193

189194
source.subscribe({ next, complete });
190195
expect(results).to.deep.equal(['Hi', 'done']);
@@ -195,7 +200,7 @@ describe('Observable', () => {
195200
const results: any[] = [];
196201
const error = function (value: string) {
197202
results.push(value);
198-
}
203+
};
199204

200205
source.subscribe({ error });
201206
expect(results).to.deep.equal(['an error']);
@@ -218,15 +223,16 @@ describe('Observable', () => {
218223
let mutatedByNext = false;
219224
let mutatedByComplete = false;
220225

221-
source.subscribe(
222-
{ next: (x) => {
226+
source.subscribe({
227+
next: (x) => {
223228
nexted = x;
224229
mutatedByNext = true;
225-
}, complete: () => {
230+
},
231+
complete: () => {
226232
completed = true;
227233
mutatedByComplete = true;
228-
} }
229-
);
234+
},
235+
});
230236

231237
expect(mutatedByNext).to.be.true;
232238
expect(mutatedByComplete).to.be.true;
@@ -387,15 +393,16 @@ describe('Observable', () => {
387393
};
388394
})
389395
.pipe(tap(() => (times += 1)))
390-
.subscribe(
391-
{ next: function () {
396+
.subscribe({
397+
next: function () {
392398
if (times === 2) {
393399
subscription.unsubscribe();
394400
}
395-
}, error: function () {
401+
},
402+
error: function () {
396403
errorCalled = true;
397-
} }
398-
);
404+
},
405+
});
399406
});
400407

401408
it('should ignore complete messages after unsubscription', (done) => {
@@ -419,15 +426,16 @@ describe('Observable', () => {
419426
};
420427
})
421428
.pipe(tap(() => (times += 1)))
422-
.subscribe(
423-
{ next: function () {
429+
.subscribe({
430+
next: function () {
424431
if (times === 2) {
425432
subscription.unsubscribe();
426433
}
427-
}, complete: function () {
434+
},
435+
complete: function () {
428436
completeCalled = true;
429-
} }
430-
);
437+
},
438+
});
431439
});
432440

433441
describe('when called with an anonymous observer', () => {
@@ -463,7 +471,7 @@ describe('Observable', () => {
463471
},
464472
};
465473

466-
throwError(() => ('bad')).subscribe(o);
474+
throwError(() => 'bad').subscribe(o);
467475
}
468476
);
469477

@@ -592,13 +600,14 @@ describe('Observable', () => {
592600
});
593601

594602
badObservable.subscribe({
595-
error: () => { /* do nothing */ }
603+
error: () => {
604+
/* do nothing */
605+
},
596606
});
597607

598608
expect(called).to.be.true;
599609
});
600610

601-
602611
it('should handle empty string sync errors', () => {
603612
const badObservable = new Observable(() => {
604613
throw '';
@@ -609,7 +618,7 @@ describe('Observable', () => {
609618
error: (err) => {
610619
caught = true;
611620
expect(err).to.equal('');
612-
}
621+
},
613622
});
614623
expect(caught).to.be.true;
615624
});
@@ -627,11 +636,12 @@ describe('Observable', () => {
627636
map((x) => x + x),
628637
map((x) => x + '!!!')
629638
)
630-
.subscribe(
631-
{ next: (x) => {
639+
.subscribe({
640+
next: (x) => {
632641
expect(x).to.equal('testtest!!!');
633-
}, complete: done }
634-
);
642+
},
643+
complete: done,
644+
});
635645
});
636646

637647
it('should return the same observable if there are no arguments', () => {
@@ -643,11 +653,11 @@ describe('Observable', () => {
643653
it('should allow any kind of piped function', () => {
644654
const source = of('test');
645655
const result = source.pipe(
646-
source => source instanceof Observable,
647-
isObservable => isObservable ? 'Well hello, there.' : 'Huh?'
656+
(source) => source instanceof Observable,
657+
(isObservable) => (isObservable ? 'Well hello, there.' : 'Huh?')
648658
);
649659
expect(result).to.equal('Well hello, there.');
650-
})
660+
});
651661
});
652662

653663
it('should not swallow internal errors', (done) => {
@@ -658,29 +668,29 @@ describe('Observable', () => {
658668
done();
659669
};
660670

661-
new Observable(subscriber => {
671+
new Observable((subscriber) => {
662672
subscriber.error('test');
663673
throw 'bad';
664674
}).subscribe({
665-
error: err => {
675+
error: (err) => {
666676
expect(err).to.equal('test');
667-
}
677+
},
668678
});
669679
});
670680

671681
// Discussion here: https://github.com/ReactiveX/rxjs/issues/5370
672682
it.skip('should handle sync errors within a test scheduler', () => {
673683
const observable = of(4).pipe(
674-
map(n => {
675-
if (n === 4) {
676-
throw 'four!';
684+
map((n) => {
685+
if (n === 4) {
686+
throw 'four!';
677687
}
678688
return n;
679689
}),
680-
catchError((err, source) => source),
690+
catchError((err, source) => source)
681691
);
682692

683-
rxTestScheduler.run(helpers => {
693+
rxTestScheduler.run((helpers) => {
684694
const { expectObservable } = helpers;
685695
expectObservable(observable).toBe('-');
686696
});
@@ -694,14 +704,13 @@ describe('Observable', () => {
694704

695705
let thrownError: any = undefined;
696706
source.subscribe({
697-
error: err => thrownError = err
707+
error: (err) => (thrownError = err),
698708
});
699709

700710
expect(thrownError).to.be.an.instanceOf(RangeError);
701711
expect(thrownError.message).to.equal('Maximum call stack size exceeded');
702712
});
703713

704-
705714
describe('As an async iterable', () => {
706715
it('should be able to be used with for-await-of', async () => {
707716
const source = new Observable<number>((subscriber) => {
@@ -727,13 +736,13 @@ describe('Observable', () => {
727736

728737
subscriber.next(1);
729738
subscriber.next(2);
730-
739+
731740
// NOTE that we are NOT calling `subscriber.complete()` here.
732741
// therefore the teardown below would never be called naturally
733742
// by the observable unless it was unsubscribed.
734743
return () => {
735744
activeSubscriptions--;
736-
}
745+
};
737746
});
738747

739748
const results: number[] = [];
@@ -759,7 +768,7 @@ describe('Observable', () => {
759768
try {
760769
for await (const value of source) {
761770
results.push(value);
762-
throw new Error('wee')
771+
throw new Error('wee');
763772
}
764773
} catch {
765774
// Ignore
@@ -786,7 +795,7 @@ describe('Observable', () => {
786795
thrownError = err;
787796
}
788797

789-
expect(thrownError?.message).to.equal('wee')
798+
expect(thrownError?.message).to.equal('wee');
790799
expect(results).to.deep.equal([1, 2]);
791800
});
792801

@@ -826,7 +835,7 @@ describe('Observable', () => {
826835
expect(results).to.deep.equal([1, 2, 3]);
827836
});
828837

829-
it ('should handle situations where values from the observable are arriving faster than the are being consumed by the async iterator', async () => {
838+
it('should handle situations where values from the observable are arriving faster than the are being consumed by the async iterator', async () => {
830839
const subject = new Subject<number>();
831840

832841
const results: any[] = [];
@@ -838,7 +847,7 @@ describe('Observable', () => {
838847
results.push(result.value);
839848
});
840849
subject.next(1);
841-
await first
850+
await first;
842851
expect(results).to.deep.equal([1]);
843852

844853
// push values through the observable that aren't yet consumed by the async iterator
@@ -861,13 +870,9 @@ describe('Observable', () => {
861870
const asyncIterator = subject[Symbol.asyncIterator]();
862871

863872
// Queue up three promises, but don't await them.
864-
const allPending = Promise.all([
865-
asyncIterator.next(),
866-
asyncIterator.next(),
867-
asyncIterator.next(),
868-
]).then((allResults) => {
869-
results.push(...allResults)
870-
})
873+
const allPending = Promise.all([asyncIterator.next(), asyncIterator.next(), asyncIterator.next()]).then((allResults) => {
874+
results.push(...allResults);
875+
});
871876

872877
expect(results).to.deep.equal([]);
873878

@@ -893,7 +898,7 @@ describe('Observable', () => {
893898
asyncIterator.next().catch((err: any) => results.push(err)),
894899
asyncIterator.next().catch((err: any) => results.push(err)),
895900
asyncIterator.next().catch((err: any) => results.push(err)),
896-
])
901+
]);
897902

898903
expect(results).to.deep.equal([]);
899904

@@ -915,7 +920,7 @@ describe('Observable', () => {
915920
state = 'subscribed';
916921
return () => {
917922
state = 'unsubscribed';
918-
}
923+
};
919924
});
920925

921926
const asyncIterator = source[Symbol.asyncIterator]();
@@ -930,10 +935,10 @@ describe('Observable', () => {
930935
let state = 'idle';
931936
const source = new Observable<number>((subscriber) => {
932937
state = 'subscribed';
933-
subscriber.next(0)
938+
subscriber.next(0);
934939
return () => {
935940
state = 'unsubscribed';
936-
}
941+
};
937942
});
938943

939944
const asyncIterator = source[Symbol.asyncIterator]();
@@ -948,4 +953,4 @@ describe('Observable', () => {
948953
expect(state).to.equal('unsubscribed');
949954
});
950955
});
951-
});
956+
});

0 commit comments

Comments
 (0)