Skip to content

Commit 5c18add

Browse files
committed
[Bugfix release] Ensure jQuery “monkey patch” are included via modules.
This both tidies up the code, but also ensures embroider compatibility For those users with ember 2.27.x but still have jQuery
1 parent 16118c3 commit 5c18add

File tree

3 files changed

+27
-45
lines changed

3 files changed

+27
-45
lines changed

addon-test-support/@ember/test-helpers/settled.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import { _backburner } from '@ember/runloop';
33
import Ember from 'ember';
44

5+
import EmberApplicationInstance from '@ember/application/instance';
6+
57
import { nextTick } from './-utils';
68
import waitUntil from './wait-until';
79
import { hasPendingTransitions } from './setup-application-context';
@@ -30,6 +32,31 @@ const _internalPendingRequests = (() => {
3032
return () => 0;
3133
})();
3234

35+
if (typeof jQuery !== 'undefined' && _internalPendingRequests) {
36+
// This exists to ensure that the AJAX listeners setup by Ember itself
37+
// (which as of 2.17 are not properly torn down) get cleared and released
38+
// when the application is destroyed. Without this, any AJAX requests
39+
// that happen _between_ acceptance tests will always share
40+
// `pendingRequests`.
41+
//
42+
// This can be removed once Ember 4.0.0 is released
43+
EmberApplicationInstance.reopen({
44+
willDestroy(...args: any[]) {
45+
46+
const internalPendingRequests= _internalPendingRequests();
47+
48+
if (internalPendingRequests === 0) { return; }
49+
50+
jQuery(document).off('ajaxSend', internalPendingRequests.incrementPendingRequests);
51+
jQuery(document).off('ajaxComplete', internalPendingRequests.decrementPendingRequests);
52+
53+
internalPendingRequests.clearPendingRequests();
54+
55+
this._super(...args);
56+
},
57+
});
58+
}
59+
3360
let requests: XMLHttpRequest[];
3461

3562
/**

index.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ const debugTree = BroccoliDebug.buildDebugCallback('ember-test-helpers');
66
module.exports = {
77
name: require('./package').name,
88

9-
included() {
10-
this._super.included.apply(this, arguments);
11-
12-
this.import('vendor/monkey-patches.js', { type: 'test' });
13-
},
14-
159
treeForAddonTestSupport(tree) {
1610
// intentionally not calling _super here
1711
// so that can have our `import`'s be

vendor/monkey-patches.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)