Skip to content

Commit

Permalink
Add monkey patch to ensure global ajaxSend listener is cleaned up.
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjblue committed Dec 13, 2017
1 parent 6027531 commit c615d7e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
module.exports = {
name: 'ember-test-helpers',

included() {
this.import('vendor/monkey-patches.js', { type: 'test' });
},

treeForAddonTestSupport(tree) {
// intentionally not calling _super here
// so that can have our `import`'s be
Expand Down
35 changes: 35 additions & 0 deletions vendor/monkey-patches.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* globals require, Ember, jQuery */

(function() {
if (typeof jQuery !== 'undefined') {
var _Ember;
if (typeof Ember !== 'undefined') {
_Ember = Ember;
} else {
_Ember = require('ember').default;
}

var pendingRequests;
if (Ember.__loader.registry['ember-testing/test/pending_requests']) {
pendingRequests = Ember.__loader.require('ember-testing/test/pending_requests');
}

if (pendingRequests) {
// This exists to ensure that the AJAX listeners setup by Ember itself
// (which as of 2.17 are not properly torn down) get cleared and released
// when the application is destroyed. Without this, any AJAX requests
// that happen _between_ when acceptance tests will always share
// `pendingRequests`.
_Ember.Application.reopen({
willDestroy() {
jQuery(document).off('ajaxSend', pendingRequests.incrementPendingRequests);
jQuery(document).off('ajaxComplete', pendingRequests.decrementPendingRequests);

pendingRequests.clearPendingRequests();

this._super.apply(this, arguments);
},
});
}
}
})();

0 comments on commit c615d7e

Please sign in to comment.