Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

fix(testabilityPatch): reset cache after memory leak detection #13013

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions test/helpers/testabilityPatch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global jQuery: true, uid: true */
/* global jQuery: true, uid: true, jqCache: true */
'use strict';

/**
Expand All @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -84,7 +88,6 @@ afterEach(function() {
}
}


// 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) {
Expand Down Expand Up @@ -133,14 +136,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;
}


Expand Down