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

Working with asynchronously rejected promises. #24

Closed
jamiemill opened this issue Apr 7, 2013 · 5 comments
Closed

Working with asynchronously rejected promises. #24

jamiemill opened this issue Apr 7, 2013 · 5 comments

Comments

@jamiemill
Copy link
Contributor

I'm having trouble using this library on promises that are resolved asynchronously.

I assumed I could write something like this:

(where getPendingPromise() is a function that returns a promise that will resolve in a few milliseconds)

it('eventually fails with error', function(done) {
    var promise = getPendingPromise();
    promise.should.be.rejected.with('Some Error').and.notify(done);
});

In the code above, my promise is being resolved in the background, and I assumed this library would wait for resolution before making its assertion.

But what actually happens is it times out and done is never called.

If I change the code to add a timeout, then the test passes:

it('eventually fails with error', function(done) {
    var promise = getPendingPromise();
    setTimeout(function() {
        promise.should.be.rejected.with('Some Error').and.notify(done);
    }, 1000);
});

So I wonder if this library can only work with resolved promises? All the internal tests seem to be articulated with already-resolved promises (the fulfilledPromise() and rejectedPromise() factories generate them).

Any clarification would be appreciated.

@domenic
Copy link
Collaborator

domenic commented Apr 8, 2013

Wow, that is definitely supposed to work, and I'm embarrassed the test cases don't include such tests. Thanks for catching it.

I'll be spending more time on this package in the near future (i.e. during the upcoming week), and will be sure to get this straightened out then.

@smazurov
Copy link

smazurov commented Aug 7, 2013

Any headway on this?

@domenic
Copy link
Collaborator

domenic commented Aug 7, 2013

I have a rewrite halfway done, I will push it to a branch tonight and if I have time do some work on it. Thanks as always for the prompt; more people getting hit by something does push it up higher in my priority queue.

@domenic
Copy link
Collaborator

domenic commented Aug 8, 2013

Rewrite branch pushed so you guys can see some progress at least https://github.com/domenic/chai-as-promised/tree/rewrite but no time to work on it tonight, I think I'm starting to feel sick :-/. This weekend!! I keep saying that, but really, I should be able to make it work this time!!!

@smazurov
Copy link

awesome, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants