Skip to content

Commit

Permalink
fix(isArrayLike): reject functions because functions have "length" (#…
Browse files Browse the repository at this point in the history
…3562)

* fix(isArrayLike): reject functions because functions have "length"

* fix(isArrayLike): Undoing auto-formatting changes
  • Loading branch information
johnlindquist authored and benlesh committed Apr 13, 2018
1 parent 9217a03 commit c9570df
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 23 additions & 1 deletion spec/observables/from-spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from 'chai';
import { TestScheduler } from 'rxjs/testing';
import { asyncScheduler, of, from, Observable, asapScheduler, Observer } from 'rxjs';
import { asyncScheduler, of, from, Observable, asapScheduler, Observer, observable, Subject } from 'rxjs';
import { first } from 'rxjs/operators';

// tslint:disable:no-any
declare const asDiagram: any;
Expand Down Expand Up @@ -118,5 +119,26 @@ describe('from', () => {
);
expect(nextInvoked).to.equal(false);
});
it(`should accept a function`, (done) => {
const subject = new Subject();
const handler = (...args: any[]) => subject.next(...args);
handler[observable] = () => subject;
let nextInvoked = false;

from((handler as any)).pipe(first()).subscribe(
(x) => {
nextInvoked = true;
expect(x).to.equal('x');
},
(x) => {
done(new Error('should not be called'));
},
() => {
expect(nextInvoked).to.equal(true);
done();
}
);
handler('x');
});
}
});
2 changes: 1 addition & 1 deletion src/internal/util/isArrayLike.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const isArrayLike = (<T>(x: any): x is ArrayLike<T> => x && typeof x.length === 'number');
export const isArrayLike = (<T>(x: any): x is ArrayLike<T> => x && typeof x.length === 'number' && typeof x !== 'function');

0 comments on commit c9570df

Please sign in to comment.