diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js
index e3be73835e4d..987b4d32b458 100644
--- a/src/ngMock/angular-mocks.js
+++ b/src/ngMock/angular-mocks.js
@@ -2001,28 +2001,6 @@ angular.mock.e2e.$httpBackendDecorator =
['$rootScope', '$delegate', '$browser', createHttpBackendMock];
-angular.mock.clearDataCache = function() {
- // jQuery 2.x doesn't expose data attached to elements. We could use jQuery.cleanData
- // to clean up after elements but we'd first need to know which elements to clean up after.
- // Skip it then.
- if (window.jQuery) {
- return;
- }
-
- var key,
- cache = angular.element.cache;
-
- for(key in cache) {
- if (Object.prototype.hasOwnProperty.call(cache,key)) {
- var handle = cache[key].handle;
-
- handle && angular.element(handle.elem).off();
- delete cache[key];
- }
- }
-};
-
-
if(window.jasmine || window.mocha) {
var currentSpec = null,
@@ -2053,8 +2031,6 @@ if(window.jasmine || window.mocha) {
injector.get('$browser').pollFns.length = 0;
}
- angular.mock.clearDataCache();
-
// clean up jquery's fragment cache
angular.forEach(angular.element.fragments, function(val, key) {
delete angular.element.fragments[key];
diff --git a/test/.jshintrc b/test/.jshintrc
index 8be371609fdb..9895e2981137 100644
--- a/test/.jshintrc
+++ b/test/.jshintrc
@@ -160,6 +160,7 @@
"provideLog": false,
"spyOnlyCallsWithArgs": false,
"createMockStyleSheet": false,
- "browserTrigger": false
+ "browserTrigger": false,
+ "jqLiteCacheSize": false
}
}
diff --git a/test/helpers/testabilityPatch.js b/test/helpers/testabilityPatch.js
index 709f34781db8..8aac59dfaf7d 100644
--- a/test/helpers/testabilityPatch.js
+++ b/test/helpers/testabilityPatch.js
@@ -28,6 +28,7 @@ beforeEach(function() {
// reset to jQuery or default to us.
bindJQuery();
+ jqLiteCacheSizeInit();
}
angular.element(document.body).empty().removeData();
@@ -128,6 +129,19 @@ function dealoc(obj) {
}
}
+
+function jqLiteCacheSize() {
+ var size = 0;
+ forEach(jqLite.cache, function() { size++; });
+ return size - jqLiteCacheSize.initSize;
+}
+jqLiteCacheSize.initSize = 0;
+
+function jqLiteCacheSizeInit() {
+ jqLiteCacheSize.initSize = jqLiteCacheSize.initSize + jqLiteCacheSize();
+}
+
+
/**
* @param {DOMElement} element
* @param {boolean=} showNgClass
diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js
index 0fb8133088c0..a03ec64781e0 100644
--- a/test/jqLiteSpec.js
+++ b/test/jqLiteSpec.js
@@ -393,18 +393,12 @@ describe('jqLite', function() {
it('should not add to the cache if the node is a comment or text node', function() {
- var calcCacheSize = function() {
- var count = 0;
- for (var k in jqLite.cache) { ++count; }
- return count;
- };
-
var nodes = jqLite(' and some text');
- expect(calcCacheSize()).toEqual(0);
+ expect(jqLiteCacheSize()).toEqual(0);
nodes.data('someKey');
- expect(calcCacheSize()).toEqual(0);
+ expect(jqLiteCacheSize()).toEqual(0);
nodes.data('someKey', 'someValue');
- expect(calcCacheSize()).toEqual(0);
+ expect(jqLiteCacheSize()).toEqual(0);
});
diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js
index 83e899345607..563bebe86114 100755
--- a/test/ng/compileSpec.js
+++ b/test/ng/compileSpec.js
@@ -1,13 +1,6 @@
'use strict';
-function calcCacheSize() {
- var size = 0;
- for(var key in jqLite.cache) { size++; }
- return size;
-}
-
-
describe('$compile', function() {
var element, directive, $compile, $rootScope;
@@ -173,26 +166,26 @@ describe('$compile', function() {
element = jqLite('
');
$compile(element.contents())($rootScope);
element.empty();
- expect(calcCacheSize()).toEqual(0);
+ expect(jqLiteCacheSize()).toEqual(0);
// Next with non-empty text nodes at the top level
// (in this case the compiler will wrap them in a )
element = jqLite('xxx
');
$compile(element.contents())($rootScope);
element.empty();
- expect(calcCacheSize()).toEqual(0);
+ expect(jqLiteCacheSize()).toEqual(0);
// Next with comment nodes at the top level
element = jqLite('');
$compile(element.contents())($rootScope);
element.empty();
- expect(calcCacheSize()).toEqual(0);
+ expect(jqLiteCacheSize()).toEqual(0);
// Finally with empty text nodes at the top level
element = jqLite('');
$compile(element.contents())($rootScope);
element.empty();
- expect(calcCacheSize()).toEqual(0);
+ expect(jqLiteCacheSize()).toEqual(0);
});
@@ -4056,29 +4049,23 @@ describe('$compile', function() {
return;
}
- var calcCacheSize = function() {
- var size = 0;
- forEach(jqLite.cache, function(item, key) { size++; });
- return size;
- };
-
inject(function($compile, $rootScope) {
- expect(calcCacheSize()).toEqual(0);
+ expect(jqLiteCacheSize()).toEqual(0);
element = $compile('')($rootScope);
- expect(calcCacheSize()).toEqual(1);
+ expect(jqLiteCacheSize()).toEqual(1);
$rootScope.$apply('xs = [0,1]');
- expect(calcCacheSize()).toEqual(2);
+ expect(jqLiteCacheSize()).toEqual(2);
$rootScope.$apply('xs = [0]');
- expect(calcCacheSize()).toEqual(1);
+ expect(jqLiteCacheSize()).toEqual(1);
$rootScope.$apply('xs = []');
- expect(calcCacheSize()).toEqual(1);
+ expect(jqLiteCacheSize()).toEqual(1);
element.remove();
- expect(calcCacheSize()).toEqual(0);
+ expect(jqLiteCacheSize()).toEqual(0);
});
});
@@ -4088,32 +4075,28 @@ describe('$compile', function() {
// jQuery 2.x doesn't expose the cache storage.
return;
}
- var calcCacheSize = function() {
- var size = 0;
- forEach(jqLite.cache, function(item, key) { size++; });
- return size;
- };
+
inject(function($compile, $rootScope) {
- expect(calcCacheSize()).toEqual(0);
+ expect(jqLiteCacheSize()).toEqual(0);
element = $compile('')($rootScope);
$rootScope.$apply('xs = [0,1]');
// At this point we have a bunch of comment placeholders but no real transcluded elements
// So the cache only contains the root element's data
- expect(calcCacheSize()).toEqual(1);
+ expect(jqLiteCacheSize()).toEqual(1);
$rootScope.$apply('val = true');
// Now we have two concrete transcluded elements plus some comments so two more cache items
- expect(calcCacheSize()).toEqual(3);
+ expect(jqLiteCacheSize()).toEqual(3);
$rootScope.$apply('val = false');
// Once again we only have comments so no transcluded elements and the cache is back to just
// the root element
- expect(calcCacheSize()).toEqual(1);
+ expect(jqLiteCacheSize()).toEqual(1);
element.remove();
// Now we've even removed the root element along with its cache
- expect(calcCacheSize()).toEqual(0);
+ expect(jqLiteCacheSize()).toEqual(0);
});
});
@@ -4656,30 +4639,24 @@ describe('$compile', function() {
it('should not leak memory with nested transclusion', function() {
- var calcCacheSize = function() {
- var count = 0;
- for (var k in jqLite.cache) { ++count; }
- return count;
- };
-
inject(function($compile, $rootScope) {
var size;
- expect(calcCacheSize()).toEqual(0);
+ expect(jqLiteCacheSize()).toEqual(0);
element = jqLite('');
$compile(element)($rootScope.$new());
$rootScope.nums = [0,1,2];
$rootScope.$apply();
- size = calcCacheSize();
+ size = jqLiteCacheSize();
$rootScope.nums = [3,4,5];
$rootScope.$apply();
- expect(calcCacheSize()).toEqual(size);
+ expect(jqLiteCacheSize()).toEqual(size);
element.remove();
- expect(calcCacheSize()).toEqual(0);
+ expect(jqLiteCacheSize()).toEqual(0);
});
});
});
diff --git a/test/ngMock/angular-mocksSpec.js b/test/ngMock/angular-mocksSpec.js
index 06caa86c4cb7..d8e5b2226d1a 100644
--- a/test/ngMock/angular-mocksSpec.js
+++ b/test/ngMock/angular-mocksSpec.js
@@ -705,72 +705,6 @@ describe('ngMock', function() {
});
- describe('angular.mock.clearDataCache', function() {
- if (window.jQuery) {
- // jQuery 2.x doesn't expose the cache storage.
- return;
- }
-
- function keys(obj) {
- var keysArr = [];
- for(var key in obj) {
- if (obj.hasOwnProperty(key)) keysArr.push(key);
- }
- return keysArr.sort();
- }
-
- function browserTrigger(element, eventType) {
- element = element[0];
- if (document.createEvent) {
- var event = document.createEvent('MouseEvents');
- event.initMouseEvent(eventType, true, true, window, 0, 0, 0, 0, 0, false, false,
- false, false, 0, element);
- element.dispatchEvent(event);
- } else {
- element.fireEvent('on' + eventType);
- }
- }
-
- it('should remove data', function() {
- expect(angular.element.cache).toEqual({});
- var div = angular.element('');
- div.data('name', 'angular');
- expect(keys(angular.element.cache)).not.toEqual([]);
- angular.mock.clearDataCache();
- expect(keys(angular.element.cache)).toEqual([]);
- });
-
- it('should deregister event handlers', function() {
- expect(keys(angular.element.cache)).toEqual([]);
- var log = '';
- var div = angular.element('');
-
- // crazy IE9 requires div to be connected to render DOM for click event to work
- // mousemove works even when not connected. This is a heisen-bug since stepping
- // through the code makes the test pass. Viva IE!!!
- angular.element(document.body).append(div);
-
- div.on('click', function() { log += 'click1;'; });
- div.on('click', function() { log += 'click2;'; });
- div.on('mousemove', function() { log += 'mousemove;'; });
-
- browserTrigger(div, 'click');
- browserTrigger(div, 'mousemove');
- expect(log).toEqual('click1;click2;mousemove;');
- log = '';
-
- angular.mock.clearDataCache();
-
- browserTrigger(div, 'click');
- browserTrigger(div, 'mousemove');
- expect(log).toEqual('');
- expect(keys(angular.element.cache)).toEqual([]);
-
- div.remove();
- });
- });
-
-
describe('jasmine module and inject', function(){
var log;