Skip to content

Commit

Permalink
test(fromPromise): ensure Observables can be created from other promi…
Browse files Browse the repository at this point in the history
…se implementations
  • Loading branch information
midnight-wonderer committed Apr 2, 2017
1 parent 8b20019 commit a0b2f1a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions spec/observables/from-promise-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,26 @@ describe('Observable.fromPromise', () => {
});
});

it('should accept PromiseLike object for interoperability', (done: MochaDone) => {
class CustomPromise<T> implements PromiseLike<T> {
constructor(private promise: PromiseLike<T>) {
}
then(onFulfilled?: ((value: T) => (PromiseLike<T> | T)) | any | any,
onRejected?: ((reason: any) => (PromiseLike<T> | T)) | any | any): PromiseLike<T> {
return new CustomPromise(this.promise.then(onFulfilled, onRejected));
};
}
const promise = new CustomPromise(Promise.resolve(42));
Observable.fromPromise(promise)
.subscribe(
(x: number) => { expect(x).to.equal(42); },
() => {
done(new Error('should not be called'));
}, () => {
done();
});
});

it('should emit a value from a resolved promise on a separate scheduler', (done: MochaDone) => {
const promise = Promise.resolve(42);
Observable.fromPromise(promise, Rx.Scheduler.asap)
Expand Down

0 comments on commit a0b2f1a

Please sign in to comment.