Skip to content

Commit

Permalink
style(test): update specs lint, hint friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Feb 23, 2016
1 parent f692ea4 commit 3f18563
Show file tree
Hide file tree
Showing 65 changed files with 518 additions and 471 deletions.
1 change: 1 addition & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ module.exports = function (config) {

// list of files / patterns to load in the browser
files: [
'node_modules/babel-polyfill/dist/polyfill.js',
'tmp/helpers/marble-testing.js',
'tmp/helpers/test-helper.js',
'tmp/helpers/ajax-helper.js',
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"build_docs": "npm run build_es6 && npm run tests2png && esdoc -c esdoc.json",
"publish_docs": "./publish_docs.sh",
"lint_perf": "eslint perf/",
"lint_spec": "eslint spec/",
"lint_spec": "tslint -c tslint.json spec/*.ts spec/**/*.ts spec/**/**/*.ts",
"lint_src": "tslint -c tslint.json src/*.ts src/**/*.ts src/**/**/*.ts",
"lint": "npm run lint_src && npm run lint_spec && npm run lint_perf",
"copy_src": "cp -r src/ dist/cjs/src && cp -r src/ dist/amd/src && cp -r src/ dist/es6/src",
Expand Down Expand Up @@ -93,6 +93,7 @@
},
"homepage": "https://github.com/ReactiveX/RxJS",
"devDependencies": {
"babel-polyfill": "6.5.0",
"benchmark": "1.0.0",
"benchpress": "2.0.0-beta.1",
"browserify": "13.0.0",
Expand Down
2 changes: 1 addition & 1 deletion spec/Notification-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Rx from '../dist/cjs/Rx';
import {expectObservable} from './helpers/marble-testing';
import {it, DoneSignature} from './helpers/test-helper';
import {it} from './helpers/test-helper';

const Notification = Rx.Notification;

Expand Down
39 changes: 22 additions & 17 deletions spec/Observable-spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import * as Rx from '../dist/cjs/Rx';
import {hot, cold, expectObservable, expectSubscriptions} from './helpers/marble-testing';
import {it, DoneSignature} from './helpers/test-helper';

const Subscriber = Rx.Subscriber;
const Observable = Rx.Observable;

declare var __root__: any;
declare const __root__: any;

function expectFullObserver(val) {
expect(typeof val).toBe('object');
Expand All @@ -28,8 +27,8 @@ describe('Observable', () => {

describe('forEach', () => {
it('should iterate and return a Promise', (done: DoneSignature) => {
const expected = [1,2,3];
const result = Observable.of(1,2,3).forEach(function (x) {
const expected = [1, 2, 3];
const result = Observable.of(1, 2, 3).forEach(function (x) {
expect(x).toBe(expected.shift());
}, null, Promise)
.then(done);
Expand Down Expand Up @@ -67,9 +66,9 @@ describe('Observable', () => {
});

it('should accept a thisArg argument', (done: DoneSignature) => {
const expected = [1,2,3];
const expected = [1, 2, 3];
const thisArg = {};
const result = Observable.of(1,2,3).forEach(function (x) {
const result = Observable.of(1, 2, 3).forEach(function (x) {
expect(this).toBe(thisArg);
expect(x).toBe(expected.shift());
}, thisArg, Promise)
Expand All @@ -80,15 +79,15 @@ describe('Observable', () => {

it('should reject promise if nextHandler throws', (done: DoneSignature) => {
const results = [];
Observable.of(1,2,3).forEach((x: number) => {
Observable.of(1, 2, 3).forEach((x: number) => {
if (x === 3) {
throw new Error('NO THREES!');
}
results.push(x);
}, null)
.then(<any>done.fail, function (err) {
expect(err).toEqual(new Error('NO THREES!'));
expect(results).toEqual([1,2]);
expect(results).toEqual([1, 2]);
})
.then(done);
});
Expand Down Expand Up @@ -142,7 +141,9 @@ describe('Observable', () => {
};
});

const sub = source.subscribe(() => { });
const sub = source.subscribe(() => {
//noop
});
expect(sub instanceof Rx.Subscription).toBe(true);
expect(unsubscribeCalled).toBe(false);
expect(typeof sub.unsubscribe).toBe('function');
Expand Down Expand Up @@ -209,7 +210,7 @@ describe('Observable', () => {
it('should accept an anonymous observer with just a next function and call the next function in the context' +
' of the anonymous observer', (done: DoneSignature) => {
//intentionally not using lambda to avoid typescript's this context capture
var o = {
const o = {
next: function next(x) {
expect(this).toBe(o);
expect(x).toBe(1);
Expand All @@ -223,7 +224,7 @@ describe('Observable', () => {
it('should accept an anonymous observer with just an error function and call the error function in the context' +
' of the anonymous observer', (done: DoneSignature) => {
//intentionally not using lambda to avoid typescript's this context capture
var o = {
const o = {
error: function error(err) {
expect(this).toBe(o);
expect(err).toBe('bad');
Expand All @@ -237,7 +238,7 @@ describe('Observable', () => {
it('should accept an anonymous observer with just a complete function and call the complete function in the' +
' context of the anonymous observer', (done: DoneSignature) => {
//intentionally not using lambda to avoid typescript's this context capture
var o = {
const o = {
complete: function complete() {
expect(this).toBe(o);
done();
Expand All @@ -260,7 +261,7 @@ describe('Observable', () => {
let unsubscribeCalled = false;

//intentionally not using lambda to avoid typescript's this context capture
var o = {
const o = {
next: function next(x) {
expect(this).toBe(o);
throw x;
Expand Down Expand Up @@ -293,7 +294,9 @@ describe('Observable', () => {

describe('Observable.create', () => {
it('should create an Observable', () => {
const result = Observable.create(() => { });
const result = Observable.create(() => {
//noop
});
expect(result instanceof Observable).toBe(true);
});

Expand All @@ -306,14 +309,16 @@ describe('Observable.create', () => {
});

expect(called).toBe(false);
result.subscribe(() => { });
result.subscribe(() => {
//noop
});
expect(called).toBe(true);
});
});

describe('Observable.lift', () => {
it('should be overrideable in a custom Observable type that composes', (done: DoneSignature) => {
class MyCustomObservable<T> extends Rx.Observable<T>{
class MyCustomObservable<T> extends Rx.Observable<T> {
lift<R>(operator: Rx.Operator<T, R>): Rx.Observable<R> {
const observable = new MyCustomObservable<R>();
(<any>observable).source = this;
Expand Down Expand Up @@ -357,7 +362,7 @@ describe('Observable.lift', () => {

// The custom Operator
class LogOperator<T, R> extends Rx.Operator<T, R> {
constructor(private childOperator: Rx.Operator<T,R>) {
constructor(private childOperator: Rx.Operator<T, R>) {
super();
}

Expand Down
43 changes: 22 additions & 21 deletions spec/Subject-spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as Rx from '../dist/cjs/Rx';
import {hot, cold, expectObservable, expectSubscriptions} from './helpers/marble-testing';
import {hot, expectObservable} from './helpers/marble-testing';
import {it, DoneSignature} from './helpers/test-helper';

const Subject = Rx.Subject;
const asap = Rx.Scheduler.asap;
const Observable = Rx.Observable;

describe('Subject', () => {
Expand Down Expand Up @@ -94,8 +93,8 @@ describe('Subject', () => {

subscription3.unsubscribe();

expect(results1).toEqual([5,6,7]);
expect(results2).toEqual([6,7,8]);
expect(results1).toEqual([5, 6, 7]);
expect(results2).toEqual([6, 7, 8]);
expect(results3).toEqual([11]);
});

Expand Down Expand Up @@ -142,8 +141,8 @@ describe('Subject', () => {

subscription3.unsubscribe();

expect(results1).toEqual([5,6,7]);
expect(results2).toEqual([6,7,'C']);
expect(results1).toEqual([5, 6, 7]);
expect(results2).toEqual([6, 7, 'C']);
expect(results3).toEqual(['C']);
});

Expand Down Expand Up @@ -190,8 +189,8 @@ describe('Subject', () => {

subscription3.unsubscribe();

expect(results1).toEqual([5,6,7]);
expect(results2).toEqual([6,7,'E']);
expect(results1).toEqual([5, 6, 7]);
expect(results2).toEqual([6, 7, 'E']);
expect(results3).toEqual(['E']);
});

Expand Down Expand Up @@ -263,15 +262,15 @@ describe('Subject', () => {
subject.unsubscribe();

expect(() => {
const subscription3 = subject.subscribe(
subject.subscribe(
function (x) { results3.push(x); },
function (e) { results3.push('E'); },
() => { results3.push('C'); }
);
}).toThrow();

expect(results1).toEqual([1,2,3,4,5]);
expect(results2).toEqual([3,4,5]);
expect(results1).toEqual([1, 2, 3, 4, 5]);
expect(results2).toEqual([3, 4, 5]);
expect(results3).toEqual([]);
});

Expand Down Expand Up @@ -307,9 +306,9 @@ describe('Subject', () => {
auxSubject.next('c');
auxSubject.next('d');

expect(results1).toEqual([1,2,3]);
expect(results1).toEqual([1, 2, 3]);
expect(subscription2.isUnsubscribed).toBe(true);
expect(results2).toEqual(['a','b']);
expect(results2).toEqual(['a', 'b']);
});

it('should allow ad-hoc subscription to be removed from itself', () => {
Expand Down Expand Up @@ -345,9 +344,9 @@ describe('Subject', () => {
auxSubject.next('c');
auxSubject.next('d');

expect(results1).toEqual([1,2,3]);
expect(results1).toEqual([1, 2, 3]);
expect(subscription2.isUnsubscribed).toBe(false);
expect(results2).toEqual(['a','b','c','d']);
expect(results2).toEqual(['a', 'b', 'c', 'd']);
});

it('should not allow values to be nexted after a return', (done: DoneSignature) => {
Expand All @@ -367,9 +366,11 @@ describe('Subject', () => {
const subject = new Subject();

const sub1 = subject.subscribe(function (x) {
//noop
});

const sub2 = subject.subscribe(function (x) {
//noop
});

expect(subject.observers.length).toBe(2);
Expand All @@ -382,7 +383,7 @@ describe('Subject', () => {

it('should have a static create function that works', () => {
expect(typeof Subject.create).toBe('function');
const source = Observable.of(1,2,3,4,5);
const source = Observable.of(1, 2, 3, 4, 5);
const nexts = [];
const output = [];

Expand Down Expand Up @@ -418,17 +419,17 @@ describe('Subject', () => {
sub.next('c');
sub.complete();

expect(nexts).toEqual(['a','b','c']);
expect(nexts).toEqual(['a', 'b', 'c']);
expect(complete).toBe(true);
expect(error).toBe(undefined);

expect(output).toEqual([1,2,3,4,5]);
expect(output).toEqual([1, 2, 3, 4, 5]);
expect(outputComplete).toBe(true);
});

it('should have a static create function that works also to raise errors', () => {
expect(typeof Subject.create).toBe('function');
const source = Observable.of(1,2,3,4,5);
const source = Observable.of(1, 2, 3, 4, 5);
const nexts = [];
const output = [];

Expand Down Expand Up @@ -464,11 +465,11 @@ describe('Subject', () => {
sub.next('c');
sub.error('boom');

expect(nexts).toEqual(['a','b','c']);
expect(nexts).toEqual(['a', 'b', 'c']);
expect(complete).toBe(false);
expect(error).toBe('boom');

expect(output).toEqual([1,2,3,4,5]);
expect(output).toEqual([1, 2, 3, 4, 5]);
expect(outputComplete).toBe(true);
});

Expand Down
9 changes: 4 additions & 5 deletions spec/helpers/ajax-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class MockWebSocket {
const sent = this.sent;
const length = sent.length;

return length > 0 ? sent[length -1] : undefined;
return length > 0 ? sent[length - 1] : undefined;
}

triggerClose(e: any): void {
Expand Down Expand Up @@ -75,8 +75,8 @@ export class MockWebSocket {

removeEventListener(name: string, handler: any): void {
const lookup = this.handlers[name];
if(lookup) {
for (let i = lookup.length - 1; i--;) {
if (lookup) {
for (let i = lookup.length - 1; i--; ) {
if (lookup[i] === handler) {
lookup.splice(i, 1);
}
Expand Down Expand Up @@ -121,7 +121,6 @@ export class MockXMLHttpRequest {
private eventHandlers: Array<any> = [];
private readyState: number = 0;

private async: any;
private user: any;
private password: any;

Expand Down Expand Up @@ -163,7 +162,7 @@ export class MockXMLHttpRequest {
}

removeEventListener(name: string, handler: any): void {
for (let i = this.eventHandlers.length - 1; i--;) {
for (let i = this.eventHandlers.length - 1; i--; ) {
let eh = this.eventHandlers[i];
if (eh.name === name && eh.handler === handler) {
this.eventHandlers.splice(i, 1);
Expand Down
2 changes: 1 addition & 1 deletion spec/observables/bindCallback-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ describe('Observable.bindCallback', () => {
results1.push('done');
});

source.subscribe((x: number) =>{
source.subscribe((x: number) => {
results2.push(x);
}, null, () => {
results2.push('done');
Expand Down
1 change: 0 additions & 1 deletion spec/observables/bindNodeCallback-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as Rx from '../../dist/cjs/Rx.KitchenSink';
import {hot, cold, expectObservable, expectSubscriptions} from '../helpers/marble-testing';
import {it, DoneSignature} from '../helpers/test-helper';

declare const rxTestScheduler: Rx.TestScheduler;
Expand Down
2 changes: 1 addition & 1 deletion spec/observables/dom/webSocket-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {it} from '../../helpers/test-helper';
declare const __root__: any;

const Observable = Rx.Observable;
var __ws: any;
let __ws: any;

function setupMockWebSocket() {
MockWebSocket.clearSockets();
Expand Down
4 changes: 2 additions & 2 deletions spec/observables/zip-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ describe('Observable.zip', () => {
const bsubs = '^ !';
const expected = '-----x--#';

expectObservable(Observable.zip(a,b)).toBe(expected, { x: [1, 2] }, 'too bad');
expectObservable(Observable.zip(a, b)).toBe(expected, { x: [1, 2] }, 'too bad');
expectSubscriptions(a.subscriptions).toBe(asubs);
expectSubscriptions(b.subscriptions).toBe(bsubs);
});
Expand Down Expand Up @@ -570,7 +570,7 @@ describe('Observable.zip', () => {
const r = [[1, 4], [2, 5], [3, 6]];
let i = 0;

Observable.zip(a, b).subscribe((vals:Array<number>) => {
Observable.zip(a, b).subscribe((vals: Array<number>) => {
(<any>expect(vals)).toDeepEqual(r[i++]);
}, null, done);
});
Expand Down
Loading

0 comments on commit 3f18563

Please sign in to comment.