Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(isArrayLike): reject functions because functions have "length" #3562

Merged
merged 2 commits into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from should not accept a function.

from((...args) => subject.next(...args)) should not work and should error.

The change to isArrayLike I can understand, I'm uncertain about this test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if from accepts a Promise, shouldn't it be able to accept a handler?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, the function has Symbol.observable on it. I missed that. Apologies.

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');