From c9570df2ba429c85c4a2c05eb51e173ba2ef85ca Mon Sep 17 00:00:00 2001 From: John Lindquist Date: Fri, 13 Apr 2018 14:31:38 -0600 Subject: [PATCH] fix(isArrayLike): reject functions because functions have "length" (#3562) * fix(isArrayLike): reject functions because functions have "length" * fix(isArrayLike): Undoing auto-formatting changes --- spec/observables/from-spec.ts | 24 +++++++++++++++++++++++- src/internal/util/isArrayLike.ts | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/spec/observables/from-spec.ts b/spec/observables/from-spec.ts index 4917927b85..4add2e298e 100644 --- a/spec/observables/from-spec.ts +++ b/spec/observables/from-spec.ts @@ -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; @@ -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'); + }); } }); diff --git a/src/internal/util/isArrayLike.ts b/src/internal/util/isArrayLike.ts index 15da7a50f4..6f634d4d9f 100644 --- a/src/internal/util/isArrayLike.ts +++ b/src/internal/util/isArrayLike.ts @@ -1 +1 @@ -export const isArrayLike = ((x: any): x is ArrayLike => x && typeof x.length === 'number'); \ No newline at end of file +export const isArrayLike = ((x: any): x is ArrayLike => x && typeof x.length === 'number' && typeof x !== 'function'); \ No newline at end of file