-
-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add monkey patch to ensure global ajaxSend listener is cleaned up.
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}, | ||
}); | ||
} | ||
} | ||
})(); |