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

Commit

Permalink
fix(ngMock): reset cache before every test
Browse files Browse the repository at this point in the history
We don't need to have values in the cache from previous tests. This was
causing failures in all subsequent tests when a single test failed due
to a memory leak.

Now that we reset the cache each time we do not need to store the cache
size at the start of each test

Closes #13013
  • Loading branch information
petebacondarwin committed Oct 6, 2015
1 parent 7b2ecf4 commit 91b7cd9
Showing 1 changed file with 7 additions and 11 deletions.
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

0 comments on commit 91b7cd9

Please sign in to comment.