Skip to content

Commit

Permalink
Merge pull request emberjs#2722 from teddyzeenny/autorun
Browse files Browse the repository at this point in the history
Bring back autorun assertion during testing
  • Loading branch information
stefanpenner committed May 23, 2013
2 parents 00b4437 + ba9014a commit 5d16eba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/ember-metal/lib/run_loop.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ Ember.run.end = function() {
@return {void}
*/
Ember.run.schedule = function(queue, target, method) {
checkAutoRun();
backburner.schedule.apply(backburner, arguments);
};

Expand Down Expand Up @@ -233,6 +234,7 @@ Ember.run.later = function(target, method) {
@return {Object} timer
*/
Ember.run.once = function(target, method) {
checkAutoRun();
var args = slice.call(arguments);
args.unshift('actions');
return backburner.scheduleOnce.apply(backburner, args);
Expand Down Expand Up @@ -283,6 +285,7 @@ Ember.run.once = function(target, method) {
@return {Object} timer
*/
Ember.run.scheduleOnce = function(queue, target, method) {
checkAutoRun();
return backburner.scheduleOnce.apply(backburner, arguments);
};

Expand Down Expand Up @@ -377,3 +380,10 @@ Ember.run.next = function() {
Ember.run.cancel = function(timer) {
return backburner.cancel(timer);
};

// Make sure it's not an autorun during testing
function checkAutoRun() {
if (!Ember.run.currentRunLoop) {
Ember.assert("You have turned on testing mode, which disabled the run-loop's autorun. You will need to wrap any code with asynchronous side-effects in an Ember.run", !Ember.testing);
}
}
10 changes: 10 additions & 0 deletions packages/ember-metal/tests/run_loop/schedule_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,13 @@ test('prior queues should be flushed before moving on to next queue', function()

deepEqual(order, ['sync', 'actions', 'sync', 'actions', 'destroy']);
});

test('makes sure it does not trigger an autorun during testing', function() {
throws(function() {
Ember.run.schedule('actions', function() {});
});

throws(function() {
Ember.run.scheduleOnce('actions', function() {});
});
});

0 comments on commit 5d16eba

Please sign in to comment.