-
Notifications
You must be signed in to change notification settings - Fork 5
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
Promise support #7
Comments
@rendro @tandrewnichols |
Is that significantly different than describe 'myPromiseFunction', ->
Given -> someAsyncSetup()
When (done) -> myPromiseFunction().then (@result) => done()
Then -> @result == 'foo' ? |
Yes. If your promise is rejected the error is not caught by your code. And writing catch statements leads to a lot of ceremony and space, especially in coffeescript |
So what happens in mocha when the promise is rejected? |
The test fails, like if you pass an error to done |
And I assume it just hangs in mocha-given . . . ? But you mostly want to avoid having to write When (done) -> myPromiseFunction()
.success (@result) => done()
.error (@result) => done() Is that correct? (Incidentally, I think that syntax may only work in later versions of coffeescript, so the implementation might depend on what version you're using.) I'm probably the wrong one to make a decision on this, not only because this isn't actually my library, but also because I almost never use promises, so familiarity there is not as high. |
Yes I want to avoid that. I think it makes a big difference. Mostly because if it worked, the async call and result fetching could be put on one single line and I think that is a big win. |
I mean, if i just want to avoid hitting the keyboard I could solve that with snippets in my editor but supporting promises makes the code more readable IMHO |
Well, I'm a little unclear how |
Hey, I guess we would need to look into the mocha code to understand how they implement promises and how we can use that behaviour to support promises in I have the feeling this could lead to a major rewrite of the module ;) |
I think that all you need to do for it to work is to take what is returned from the Given/When function and make sure it is returned in the before funtion that is added to the suite. If it is a promise, mocha will handle it. |
Guys, I solved this by writing my own version of Given When Then from scratch.... https://github.com/TheLudd/mocha-gwt |
Mocha now has promise support. Would it be possible to also add it to mocha-given?
In mocha i can write:
It would be awesome if mocha-given supported this:
The text was updated successfully, but these errors were encountered: