-
-
Notifications
You must be signed in to change notification settings - Fork 155
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
Does beforeEach support more than 1 promise resolve? #165
Comments
We still can't use RSVP.all but a workaround that solves the issue module("Acceptance: Some Things Need Loaded Before Tests Start", {
beforeEach: function () {
application = startApp();
return promiseAwaitingThingsReady(thingOne, thingTwo);
},
afterEach: function() {
Ember.run(application, "destroy");
return promiseAwaitingThingsDestroyed();
}
}); The functions shown above might look something like this.... var promiseAwaitingThingsReady = function() {
var thingIds = arguments;
var ready = [];
return new Ember.RSVP.Promise(function(resolve) {
GLOBALTHING.on("instanceReady", function(event) {
ready.push(event.thing.name);
for (var i = 0; i < thingIds.length; i++) {
var thingId = thingIds[i];
if (ready.indexOf(item) < 0)
return;
}
}
event.removeListener();
resolve(true);
});
});
};
var promiseAwaitingThingsDestroyed = function() {
return new Ember.RSVP.Promise(function(resolve) {
if (!Object.keys(GLOBALTHING.instances).length) {
resolve(true);
return;
}
GLOBALTHING.on("reset", function(event) {
event.removeListener();
resolve(true);
});
});
}; |
This may sound crazy, but can you return a promise like: new Ember.RSVP.Promise(function (resolve) {
Ember.RSVP.all(...).then(function(){ resolve(true); });
}); |
For better/worse this is what I ended up with var promiseAwaitingThingsDestroyed = function() {
return new Ember.RSVP.Promise(function(resolve) {
if (!Object.keys(SOMEGLOBAL.instances).length) {
resolve(true);
return;
}
SOMEGLOBAL.on("reset", function(event) {
event.destoryThing();
resolve(true);
});
});
};
afterEach: function() {
Ember.run(application, "destroy");
return promiseAwaitingThingsDestroyed();
} |
that sound like a very strange issue, because beforeEach() doesn't care what kind of promise is returned. I haven't noticed any issues like that with any of the more recent releases so I'll go ahead and close this. If this issue is indeed still relevant then please let me know and reopen. |
I have a single test that does a beforeEach. Inside this beforeEach I originally had a single promise that I needed to resolve before any tests run.
That worked great - but later when I tried to resolve 2 using RSVP.all I got an error saying
Here is the new return statement that throws the above error
Here is an example ember-cli project that shows it in action
https://github.com/jcttrll/ember-rsvp-all-issue
Here is a full stack showing what blew up if this helps in any way
The text was updated successfully, but these errors were encountered: