-
Notifications
You must be signed in to change notification settings - Fork 109
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
Testing RSVP.Promises #10
Comments
No, Chai as Promised does not try to make promises fake-synchronous. If you want to expand the featureset of Sinon.JS to support different methods of fake-sync, feel free to file a bug there. It is not in scope for Chai as Promised. If you don't try to hide the asynchronicity in your tests, you can either test using the chai.expect(this.promise).to.be.fulfilled.notify(done); or using Mocha as Promised. |
Righto! This is behaving as expected http://jsfiddle.net/TqA5R/11/ it("EXPECTED TO FAIL! should not be fulfilled on reject", function(done) {
this.promise.reject();
chai.expect(this.promise).to.be.fulfilled.notify(done);
});
it("should be fulfilled on resolve", function(done) {
this.promise.resolve();
chai.expect(this.promise).to.be.fulfilled.notify(done);
}); The expected to fail fails. Thanks for the tip @domenic ! |
Glad to help! BTW I'm pretty sure the "done invoked with non-Error" is JSFiddle specific, since they use iframes and so |
Howdy! In writing some tests for code using https://github.com/tildeio/rsvp.js, we've run into unexpected behavior. The
fulfilled
assertion helper is always passing, regardless of if the promise is actually rejected.Promises in RSVP are deferred in different ways depending on your env. In Node, they are deferred with
nextTick
. In Firefox and Webkit withMutationObserver
and a disconnected DOM node. In all other envs withsetTimeout
. See https://github.com/tildeio/rsvp.js/blob/master/lib/rsvp.js#L3 for detail.This deferral means sinon's normal fake timers don't force the code to be synchronous. I was hoping this is the problem chai-as-promised was addressing. Here is a fiddle of chai-as-promised allowing an assertion that should be false:
http://jsfiddle.net/TqA5R/9/
The text was updated successfully, but these errors were encountered: