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

Observables #1898

Closed
jamiebuilds opened this issue Sep 20, 2015 · 6 comments
Closed

Observables #1898

jamiebuilds opened this issue Sep 20, 2015 · 6 comments
Labels
stale this has been inactive for a while... type: question support question

Comments

@jamiebuilds
Copy link

So there's this cool thing called Observables that is (likely) coming to the language soon (ref 1, ref 2).

They are similar to promises in a number of ways.

  • They both attempt to deal with asynchronous actions in a reasonable manner.
  • They both define a standard interface that can be implemented and extended by third parties.

Since Mocha supports returning promises in order to avoid using the done callback, it'd be nice if it did the same thing with observables:

it('should do something with an Observable', () => {
  return Observable.of(1, 2, 3).subscribe(...);
});

People are already using these with http://reactivex.io/.

cc @Blesh

@jamiebuilds
Copy link
Author

Side note: Gulp is doing the same thing with Observables in 4.0.

@benlesh
Copy link

benlesh commented Sep 21, 2015

One temporary solution for RxJS Next/5 is to use forEach rather than subscribe, as it returns a promise. But it's not ideal.

@mAAdhaTTah
Copy link

Is this something Mocha would accept a PR on?

mAAdhaTTah added a commit to mAAdhaTTah/mocha that referenced this issue Feb 25, 2017
Handles returned observables the same way we handle returned promises.
Use the shared `symbol-observable` library for interop and consume the
stream until it ends. If an error is emitted, call callback with error object
from stream.

Fixes mochajs#1898.
@ScottFreeCode
Copy link
Contributor

I'm not yet familiar with how observables are implemented under the hood, so I want to check one thing: would this interfere with making generator test functions be failures, if the latter were implemented by checking for typeof (<result> && <result>.next) === 'function' on the test return value?

Obviously, handling generators (even as automatic failures*) and handling observables can be two separate enhancements; I just want to make sure that by deciding to add either one we aren't closing off the ability to decide for or against the other.

*(In case the rationale makes this any clearer, I've come part way around on my thinking in this regard since it was last discussed: I'm still not so sure we would want Mocha to assume that the promise-unwrapping generator wrapper behavior is the one that should be default-associated with tests, but I see enough usefulness in such wrappings -- for Selenium especially -- that I think passing the test if somebody forgets the wrapper is unhelpful, and I think checking for the .next function on the returned object should be a safe enough way to do it without losing any browser support... but I suppose I should dig up the old issue on that and present my updated thoughts there.)

@mAAdhaTTah
Copy link

@ScottFreeCode For the PR I opened (#2722) I used symbol-observable, as that seems to be the consensus in the community for observable interop. If the return value has that set, we can use that to determine if we should consume the observable. Because it uses a completely different mechanism, it doesn't have any impact on support generators later.

mAAdhaTTah added a commit to mAAdhaTTah/mocha that referenced this issue Feb 27, 2017
Handles returned observables the same way we handle returned promises.
Use the shared `symbol-observable` library for interop and consume the
stream until it ends. If an error is emitted, call callback with error object
from stream.

Fixes mochajs#1898.
@drazisil drazisil added the type: question support question label Mar 30, 2017
@stale stale bot added the stale this has been inactive for a while... label Jul 29, 2017
@stale
Copy link

stale bot commented Jul 29, 2017

I am a bot that watches issues for inactivity.
This issue hasn't had any recent activity, and I'm labeling it stale. In 14 days, if there are no further comments or activity, I will close this issue.
Thanks for contributing to Mocha!

@stale stale bot closed this as completed Aug 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale this has been inactive for a while... type: question support question
Projects
None yet
Development

No branches or pull requests

5 participants