Skip to content

Commit

Permalink
Decrement requests in the next tick
Browse files Browse the repository at this point in the history
  • Loading branch information
cibernox committed Apr 20, 2018
1 parent 274ed24 commit f33dead
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 7 additions & 5 deletions packages/ember-testing/lib/test/pending_requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ export function incrementPendingRequests(_, xhr) {
}

export function decrementPendingRequests(_, xhr) {
for (let i = 0; i < requests.length; i++) {
if (xhr === requests[i]) {
requests.splice(i, 1);
break;
setTimeout(function() {
for (let i = 0; i < requests.length; i++) {
if (xhr === requests[i]) {
requests.splice(i, 1);
break;
}
}
}
}, 0);
}
6 changes: 5 additions & 1 deletion packages/ember-testing/tests/helpers_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,7 @@ if (!jQueryDisabled) {
}

[`@test pendingRequests is maintained for ajaxSend and ajaxComplete events`](assert) {
let done = assert.async();
assert.equal(pendingRequests(), 0);

let xhr = { some: 'xhr' };
Expand All @@ -1048,7 +1049,10 @@ if (!jQueryDisabled) {
assert.equal(pendingRequests(), 1, 'Ember.Test.pendingRequests was incremented');

this.trigger('ajaxComplete', xhr);
assert.equal(pendingRequests(), 0, 'Ember.Test.pendingRequests was decremented');
setTimeout(function() {
assert.equal(pendingRequests(), 0, 'Ember.Test.pendingRequests was decremented');
done();
}, 0);
}

[`@test pendingRequests is ignores ajaxComplete events from past setupForTesting calls`](
Expand Down

0 comments on commit f33dead

Please sign in to comment.