Skip to content

Commit

Permalink
chore(test): update type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Mar 3, 2016
1 parent 98e183d commit 2c1a794
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 46 deletions.
32 changes: 18 additions & 14 deletions spec/observables/dom/ajax-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {MockXMLHttpRequest} from '../../helpers/ajax-helper';
import {it} from '../../helpers/test-helper';

declare const global: any;
//declare const XMLHttpRequest: MockXMLHttpRequest;

describe('Observable.ajax', () => {
let gXHR: XMLHttpRequest;
Expand All @@ -25,16 +24,17 @@ describe('Observable.ajax', () => {
});

it('should set headers', () => {
const obj = {
const obj: Rx.AjaxRequest = {
url: '/talk-to-me-goose',
headers: {
'Content-Type': 'kenny/loggins',
'Fly-Into-The': 'Dangah Zone!',
'Take-A-Ride-Into-The': 'Danger ZoooOoone!'
}
},
method: ''
};

(<any>Rx.Observable.ajax)(obj).subscribe();
Rx.Observable.ajax(obj).subscribe();

const request = MockXMLHttpRequest.mostRecent;

Expand Down Expand Up @@ -85,10 +85,11 @@ describe('Observable.ajax', () => {
responseType: 'text',
resultSelector: (res: any) => {
throw new Error('ha! ha! fooled you!');
}
},
method: ''
};

(<any>Rx.Observable.ajax)(obj)
Rx.Observable.ajax(obj)
.subscribe((x: any) => {
throw 'should not next';
}, (err: any) => {
Expand Down Expand Up @@ -137,9 +138,10 @@ describe('Observable.ajax', () => {
const obj = {
url: '/flibbertyJibbet',
responseType: 'text',
method: ''
};

(<any>Rx.Observable.ajax)(obj)
Rx.Observable.ajax(obj)
.subscribe((x: any) => {
result = x;
}, null, () => {
Expand All @@ -166,10 +168,11 @@ describe('Observable.ajax', () => {
normalizeError: (e: any, xhr: any, type: any) => {
return xhr.response || xhr.responseText;
},
responseType: 'text'
responseType: 'text',
method: ''
};

(<any>Rx.Observable.ajax)(obj)
Rx.Observable.ajax(obj)
.subscribe((x: any) => {
throw 'should not next';
}, (err: any) => {
Expand Down Expand Up @@ -198,10 +201,11 @@ describe('Observable.ajax', () => {
normalizeError: (e: any, xhr: any, type: any) => {
return xhr.response || xhr.responseText;
},
responseType: 'text'
responseType: 'text',
method: ''
};

(<any>Rx.Observable.ajax)(obj).subscribe((x: any) => {
Rx.Observable.ajax(obj).subscribe((x: any) => {
throw 'should not next';
}, (err: any) => {
error = err;
Expand All @@ -224,8 +228,8 @@ describe('Observable.ajax', () => {

it('should succeed no settings', () => {
const expected = JSON.stringify({ foo: 'bar' });
//Type definition need to be updated
(<any>Rx.Observable.ajax)('/flibbertyJibbet')

Rx.Observable.ajax('/flibbertyJibbet')
.subscribe((x: any) => {
expect(x.status).toBe(200);
expect(x.xhr.method).toBe('GET');
Expand All @@ -245,7 +249,7 @@ describe('Observable.ajax', () => {
it('should fail no settings', () => {
const expected = JSON.stringify({ foo: 'bar' });

(<any>Rx.Observable.ajax)('/flibbertyJibbet')
Rx.Observable.ajax('/flibbertyJibbet')
.subscribe(() => {
throw 'should not have been called';
}, (x: any) => {
Expand Down
4 changes: 2 additions & 2 deletions spec/operators/distinctUntilChanged-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ describe('Observable.prototype.distinctUntilChanged()', () => {
const comparator = (x: number, y: number) => y % 2 === 1;
const keySelector = (x: number) => x % 2;

expectObservable((<any>e1).distinctUntilChanged(comparator, keySelector)).toBe(expected, {a: 1, b: 2, d: 4, f: 6});
expectObservable(e1.distinctUntilChanged(comparator, keySelector)).toBe(expected, {a: 1, b: 2, d: 4, f: 6});
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

Expand All @@ -210,7 +210,7 @@ describe('Observable.prototype.distinctUntilChanged()', () => {
return x;
};

expectObservable((<any>e1).distinctUntilChanged(null, keySelector)).toBe(expected);
expectObservable(e1.distinctUntilChanged(null, keySelector)).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
});
54 changes: 29 additions & 25 deletions spec/operators/do-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Rx from '../../dist/cjs/Rx';
import {hot, cold, expectObservable, expectSubscriptions} from '../helpers/marble-testing';
import {it, asDiagram} from '../helpers/test-helper';
import {it, asDiagram, DoneSignature} from '../helpers/test-helper';

const Observable = Rx.Observable;
const Subject = Rx.Subject;
Expand All @@ -11,7 +11,9 @@ describe('Observable.prototype.do()', () => {
const e1subs = '^ !';
const expected = '--1--2--3--|';

const result = (<any>e1).do();
const result = e1.do(() => {
//noop
});
expectObservable(result).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
Expand All @@ -38,52 +40,46 @@ describe('Observable.prototype.do()', () => {
expect(err).toBe('bad');
});

it('should handle everything with an observer', () => {
it('should handle everything with an observer', (done: DoneSignature) => {
const expected = [1, 2, 3];
const results = [];
let completeCalled = false;

Observable.of(1, 2, 3)
.do(<any>{
.do(<Rx.Observer<number>>{
next: (x: number) => {
results.push(x);
},
error: (err: any) => {
throw 'should not be called';
done.fail('should not be called');
},
complete: () => {
completeCalled = true;
expect(results).toEqual(expected);
done();
}
})
.subscribe();

expect(completeCalled).toBe(true);
expect(results).toEqual(expected);
}).subscribe();
});

it('should handle everything with a Subject', () => {
it('should handle everything with a Subject', (done: DoneSignature) => {
const expected = [1, 2, 3];
const results = [];
let completeCalled = false;
const subject = new Subject();

subject.subscribe({
next: (x: any) => {
results.push(x);
},
error: (err: any) => {
throw 'should not be called';
done.fail('should not be called');
},
complete: () => {
completeCalled = true;
expect(results).toEqual(expected);
done();
}
});

Observable.of(1, 2, 3)
.do(<any>subject)
.do(<Rx.Observer<number>>subject)
.subscribe();

expect(completeCalled).toBe(true);
expect(results).toEqual(expected);
});

it('should handle an error with a callback', () => {
Expand Down Expand Up @@ -172,7 +168,9 @@ describe('Observable.prototype.do()', () => {
const e1subs = '^ ! ';
const expected = '--1--2-- ';

const result = (<any>e1).do();
const result = e1.do(() => {
//noop
});
expectObservable(result, unsub).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
Expand All @@ -183,9 +181,11 @@ describe('Observable.prototype.do()', () => {
const expected = '--1--2-- ';
const unsub = ' ! ';

const result = (<any>e1)
const result = e1
.mergeMap((x: any) => Observable.of(x))
.do()
.do(() => {
//noop
})
.mergeMap((x: any) => Observable.of(x));

expectObservable(result, unsub).toBe(expected);
Expand All @@ -197,7 +197,9 @@ describe('Observable.prototype.do()', () => {
const e1subs = '^ !';
const expected = '--1--2--3--|';

const result = (<any>e1).do();
const result = e1.do(() => {
//noop
});
expectObservable(result).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
Expand All @@ -207,7 +209,9 @@ describe('Observable.prototype.do()', () => {
const e1subs = '^ !';
const expected = '--1--2--3--#';

const result = (<any>e1).do();
const result = e1.do(() => {
//noop
});
expectObservable(result).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
Expand Down
10 changes: 5 additions & 5 deletions spec/operators/startWith-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('Observable.prototype.startWith()', () => {
const e1subs = '^ !';
const expected = '(yz)-a--|';

expectObservable((<any>e1).startWith('y', 'z')).toBe(expected);
expectObservable(e1.startWith('y', 'z')).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

Expand Down Expand Up @@ -105,7 +105,7 @@ describe('Observable.prototype.startWith()', () => {
const expected = 's--a--b---';
const values = { s: 's', a: 'a', b: 'b' };

const result = (<any>e1).startWith('s', rxTestScheduler);
const result = e1.startWith('s', rxTestScheduler);

expectObservable(result, unsub).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -118,7 +118,7 @@ describe('Observable.prototype.startWith()', () => {
const unsub = ' ! ';
const values = { s: 's', a: 'a', b: 'b' };

const result = (<any>e1)
const result = e1
.mergeMap((x: string) => Observable.of(x))
.startWith('s', rxTestScheduler)
.mergeMap((x: string) => Observable.of(x));
Expand All @@ -141,7 +141,7 @@ describe('Observable.prototype.startWith()', () => {
const e1subs = '^ !';
const expected = 'x-a--|';

expectObservable((<any>e1).startWith(defaultStartValue, rxTestScheduler)).toBe(expected);
expectObservable(e1.startWith(defaultStartValue, rxTestScheduler)).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

Expand All @@ -150,7 +150,7 @@ describe('Observable.prototype.startWith()', () => {
const e1subs = '^ !';
const expected = '(yz)-a--|';

expectObservable((<any>e1).startWith('y', 'z', rxTestScheduler)).toBe(expected);
expectObservable(e1.startWith('y', 'z', rxTestScheduler)).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
});
1 change: 1 addition & 0 deletions src/Rx.DOM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ var Symbol = {
/* tslint:enable:no-var-keyword */

export {
AjaxRequest,
AjaxResponse,
AjaxError,
AjaxTimeoutError,
Expand Down

0 comments on commit 2c1a794

Please sign in to comment.