Skip to content

Commit

Permalink
refactor(map): throw error when not passed a function
Browse files Browse the repository at this point in the history
map will now throw an error for users that mistakenly try to use it as mapTo

related: #994
  • Loading branch information
benlesh committed Dec 9, 2015
1 parent f647eb6 commit 48c0927
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions spec/operators/map-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ describe('Observable.prototype.map()', function () {
expectSubscriptions(a.subscriptions).toBe(asubs);
});

it('should throw an error if not passed a function', function () {
expect(function () {
Observable.of(1, 2, 3).map('potato');
}).toThrow(new TypeError('argument is not a function. Are you looking for `mapTo()`?'));
});

it('should map multiple values', function () {
var a = cold('--1--2--3--|');
var asubs = '^ !';
Expand Down
3 changes: 3 additions & 0 deletions src/operator/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import {errorObject} from '../util/errorObject';
* @returns {Observable} a observable of projected values
*/
export function map<T, R>(project: (x: T, ix?: number) => R, thisArg?: any): Observable<R> {
if (typeof project !== 'function') {
throw new TypeError('argument is not a function. Are you looking for `mapTo()`?');
}
return this.lift(new MapOperator(project, thisArg));
}

Expand Down

0 comments on commit 48c0927

Please sign in to comment.