I decided that it was actually a good idea for me to use Ember.run.later
because it would potentially allow me to avoid some race conditions. I.E. if the setTime fired after the test suite had tour down, etc. So forcing the app to wait until the time has executed was a healthy thing [for me]. My real complaint was simply the time it took.
So I ended up creating a static config object that was registered with the App.register
and injected it into my views and controllers. This config contained all the desired timer values (among other things). So then in my test setup I would substitute that config object with very short timer values (1ms). This approach is a little bit over the top, I really could have used global variables, but it felt the most inline with Ember’s testing pattern.
// .....................................................
// App Initializer
var globalSettings = Ember.Object.create({
bannerTimeout: 2500
});
// Test suite will inject it's own
if(!App.testing) {
App.register('globals:settings', globalSettings);
}
App.inject('view', 'globalSettings', 'globals:settings');
App.inject('controller', 'globalSettings', 'globals:settings');
// .....................................................
// View definition
App.MyBannerView = Ember.View.extend({
/* ... */
setHideTime: function() {
Ember.run.later(this, this.hide, this.get('globalSettings.bannerTimeout'));
}.on('show')
});
// .....................................................
// Test suite example
function startApp() {
/* ... */
var globalTestSettings = Ember.Object.create({
bannerTimeout: 1
});
Ember.run(function () {
App = Application.create();
App.register('globals:settings', globalTestSettings);
App.setupForTesting();
App.injectTestHelpers();
});
/* ... */
}