diff --git a/packages/ember-testing/lib/test/pending_requests.js b/packages/ember-testing/lib/test/pending_requests.js index e03fb9ba3c8..4ba949f5ba0 100644 --- a/packages/ember-testing/lib/test/pending_requests.js +++ b/packages/ember-testing/lib/test/pending_requests.js @@ -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); } diff --git a/packages/ember-testing/tests/helpers_test.js b/packages/ember-testing/tests/helpers_test.js index fb6227abac0..8081b797845 100644 --- a/packages/ember-testing/tests/helpers_test.js +++ b/packages/ember-testing/tests/helpers_test.js @@ -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' }; @@ -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`](