Skip to content

Commit

Permalink
Merge pull request #10276 from ef4/fix-unregister-waiter
Browse files Browse the repository at this point in the history
[BUGFIX beta] Fix broken unregisterWaiter semantics
  • Loading branch information
rwjblue committed Jan 24, 2015
2 parents 006d3c9 + cefb054 commit d2d1490
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
5 changes: 1 addition & 4 deletions packages/ember-testing/lib/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Ember from "ember-metal/core";
import emberRun from "ember-metal/run_loop";
import { create } from "ember-metal/platform";
import compare from "ember-runtime/compare";
import RSVP from "ember-runtime/ext/rsvp";
import setupForTesting from "ember-testing/setup_for_testing";
import EmberApplication from "ember-application/system/application";
Expand Down Expand Up @@ -265,15 +264,13 @@ var Test = {
@since 1.2.0
*/
unregisterWaiter: function(context, callback) {
var pair;
if (!this.waiters) { return; }
if (arguments.length === 1) {
callback = context;
context = null;
}
pair = [context, callback];
this.waiters = Ember.A(this.waiters.filter(function(elt) {
return compare(elt, pair)!==0;
return !(elt[0] === context && elt[1] === callback);
}));
}
};
Expand Down
29 changes: 24 additions & 5 deletions packages/ember-testing/tests/helpers_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function cleanup() {
jQuery(document).off('ajaxComplete');
});
Test.pendingAjaxRequests = null;
Test.waiters = null;

// Other cleanup

Expand Down Expand Up @@ -250,24 +251,33 @@ QUnit.module("ember-testing: Helper methods", {
});

test("`wait` respects registerWaiters", function() {
expect(2);
expect(3);

var counter=0;
function waiter() {
return ++counter > 2;
}

var other=0;
function otherWaiter() {
return ++other > 2;
}

run(App, App.advanceReadiness);
Test.registerWaiter(waiter);
Test.registerWaiter(otherWaiter);

App.testHelpers.wait().then(function() {
equal(waiter(), true, 'should not resolve until our waiter is ready');
Test.unregisterWaiter(waiter);
equal(Test.waiters.length, 0, 'should not leave a waiter registered');
equal(Test.waiters.length, 1, 'should not leave the waiter registered');
other = 0;
return App.testHelpers.wait();
}).then(function() {
equal(otherWaiter(), true, 'other waiter is still registered');
});
});


test("`visit` advances readiness.", function() {
expect(2);

Expand Down Expand Up @@ -397,7 +407,7 @@ test("`wait` waits for outstanding timers", function() {


test("`wait` respects registerWaiters with optional context", function() {
expect(2);
expect(3);

var obj = {
counter: 0,
Expand All @@ -406,13 +416,22 @@ test("`wait` respects registerWaiters with optional context", function() {
}
};

var other=0;
function otherWaiter() {
return ++other > 2;
}

run(App, App.advanceReadiness);
Test.registerWaiter(obj, obj.ready);
Test.registerWaiter(otherWaiter);

App.testHelpers.wait().then(function() {
equal(obj.ready(), true, 'should not resolve until our waiter is ready');
Test.unregisterWaiter(obj, obj.ready);
equal(Test.waiters.length, 0, 'should not leave a waiter registered');
equal(Test.waiters.length, 1, 'should not leave the waiter registered');
return App.testHelpers.wait();
}).then(function() {
equal(otherWaiter(), true, 'other waiter should still be registered');
});
});

Expand Down

0 comments on commit d2d1490

Please sign in to comment.