-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
API Suggestion: Use an explicit callback argument for completion of async specs #178
Comments
Good idea. I've marked it as "v2" as that's where we're putting syntax changes/updates for now. Thx! |
+1, would love to see this (I was just about to request the same thing). |
This also makes promise-based code much simpler to write: the developer can just register the specified deferred into the promise e.g.
(nb: that does not work in Mocha if the code would be even nicer if it provided a "failure" callback as well, which would use whatever arguments were passed to it as the test failure report:
|
@masklinn In my opinion a spec should fail in only 2 cases, when an expectation is not met, or an uncaught exception is raised. This third and far less common failure method seems inconsistent. |
I'd like this feature as well. :) |
It's not a third failure method. There's an expectation that the promise is resolved (succeeds), if the promise is rejected (fails) then it's a failure. |
+1, would love to see this also |
mocha support this, jasmine-node already support it too, Derick Bailey published an extension to support it, so please add this feature to the core |
+1 to that |
This is implemented on master as part of 2.0. This version is not quite ready for prime time, but you can see the direction we are heading. |
Seems that work on 2.0 branch is not very active, any ETA? |
There is work going on in a couple of branches. But yes, it moves in fits-and-starts. |
I'm not sure of the status here; but a FYI on a nice alternative: The taskrunner This could be more flexible then passing in the
|
Like it! This can also be supported in addition to the callback version |
Reading through the mocha.js docs: http://visionmedia.github.com/mocha/
One awesome feature stands out. Spec blocks can accept an argument, which is a function that can be called to signify the end of an async spec.
To do the same in Jasmine, it might look like this:
I suppose you could setup a spy, and
waitsFor()
that spy to be called form the callback as well. But the point is this: you have to set all that up. Using the provided callback instead, cleans up the test greatly.I assume this works by checking the
specFunction.length
and if that is one, then we assume it's an async spec and refuse to move on until that callback is called (or spec times out of course). And if it's zero the spec runs synchronously, or can use waits/runs queues as normal.I've had to train a few people on Jasmine and the
waits()
andruns()
dance is always a sticking point of conceptual understanding. But an explicit, "done with everything in this spec" callback is a far easier API to grasp, and requires far less setup in the spec itself. In my opinion it's easier to learn, write, read and maintain.The text was updated successfully, but these errors were encountered: