diff --git a/test/helpers/testabilityPatch.js b/test/helpers/testabilityPatch.js index acc8060dea25..2b19a1e30ac8 100644 --- a/test/helpers/testabilityPatch.js +++ b/test/helpers/testabilityPatch.js @@ -1,4 +1,4 @@ -/* global jQuery: true, uid: true */ +/* global jQuery: true, uid: true, jqCache: true */ 'use strict'; /** @@ -12,6 +12,7 @@ if (window._jQuery) _jQuery.event.special.change = undefined; if (window.bindJQuery) bindJQuery(); beforeEach(function() { + // all this stuff is not needed for module tests, where jqlite and publishExternalAPI and jqLite are not global vars if (window.publishExternalAPI) { publishExternalAPI(angular); @@ -28,7 +29,10 @@ beforeEach(function() { // reset to jQuery or default to us. bindJQuery(); - jqLiteCacheSizeInit(); + + // Clear the cache to prevent memory leak failures from previous tests + // breaking subsequent tests unnecessarily + jqCache = jqLite.cache = {}; } angular.element(document.body).empty().removeData(); @@ -80,11 +84,11 @@ afterEach(function() { }); }); if (count) { + // Empty the cache to prevent further false-negatives throw new Error('Found jqCache references that were not deallocated! count: ' + count); } } - // copied from Angular.js // we need this method here so that we can run module tests with wrapped angular.js function forEachSorted(obj, iterator, context) { @@ -133,14 +137,7 @@ 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(); + return Object.keys(jqLite.cache).length; }