-
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
How do I run before and after asynchronous specs in jasmine 2.0 #526
Comments
Something more like:
|
Hmmm... So does this limit me to 3 stages and only via the artificial step On Friday, February 21, 2014, Davis W. Frank notifications@github.com
Sent with thumbs (mostly the right one, which is developing a bit of a |
You can have multiple describe('should allow multi stage asynchronisity', function () {
beforeEach(function (done) {
//set up
var initialState
// call something asynchronous
done();
});
beforeEach(function (done) {
// check some intermediate state
// call something asynchronous
done();
});
it(function (done) {
expect(middleState).not.toEqual(initialState);
// call something else asynchronous
expect(finalState).toEqual(middleState);
done();
});
}); The |
Thanks @slackersoft. I'll use that approach. I Still thinks it's a poor API if you're forced to use |
The hope is that the main Using callback functions, your test could look something like this: it("multi-stage async", function(done) {
var initialState;
somethingAsynchronous(function() {
expect(middleState).not.toEqual(initialState);
somethingElseAsync(function() {
expect(finalState).not.toEqual(middleState);
done();
});
expect(finalState).toEqual(middleState);
});
expect(middleState).toEqual(initialState);
}); Using promises (so that the expectations appear in order they are called), the same test could look like this: it("multi-stage async with promises", function(done) {
var initialState;
var promise = somethingAsynchronous();
expect(middleState).toEqual(initialState);
promise.then(function() {
expect(middleState).not.toEqual(initialState);
var innerPromise = somethingElseAsync();
expect(finalState).toEqual(middleState);
return innerPromise;
}).then(function() {
expect(finalState).not.toEqual(middleState);
done();
});
}); (Also for #530 which is related to this issue, it is worth noting that Does that help this issue? |
I don't like to be a complainer, but that's so much more boilerplate for so much less functionality. One of the major draws of Jasmine was the simple syntax (describe, it, beforeEach, etc). Now beforeEach is overloaded to mean significantly different things, the clean syntax of waits, runs is gone -- it just feels like an anti-pattern to me. |
I think you're pointing out problems that many projects run into with testing asynchronous code asynchronously. We moved to the Closing. |
The new
done()
syntax, at first glance, appears to be far less flexible than the old syntax. Using done how do I implement something like:The text was updated successfully, but these errors were encountered: