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

Commit

Permalink
fix(mocks): free up memory after every spec
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtajina committed Aug 30, 2012
1 parent 8114d55 commit 1a8642a
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/ngMock/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -1591,9 +1591,29 @@ window.jasmine && (function(window) {

afterEach(function() {
var spec = getCurrentSpec();
var injector = spec.$injector;

spec.$injector = null;
spec.$modules = null;

if (injector) {
injector.get('$rootElement').unbind();
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];
});

MockXhr.$$lastInstance = null;

angular.forEach(angular.callbacks, function(val, key) {
delete angular.callbacks[key];
});
angular.callbacks.counter = 0;
});

function getCurrentSpec() {
Expand Down Expand Up @@ -1694,7 +1714,7 @@ window.jasmine && (function(window) {
*/
window.inject = angular.mock.inject = function() {
var blockFns = Array.prototype.slice.call(arguments, 0);
var stack = new Error('Declaration Location').stack;
var errorForStack = new Error('Declaration Location');
return isSpecRunning() ? workFn() : workFn;
/////////////////////
function workFn() {
Expand All @@ -1710,10 +1730,12 @@ window.jasmine && (function(window) {
try {
injector.invoke(blockFns[i] || angular.noop, this);
} catch (e) {
if(e.stack) e.stack += '\n' + stack;
if(e.stack) e.stack += '\n' + errorForStack.stack;
throw e;
} finally {
errorForStack = null;
}
}
}
}
};
})(window);

0 comments on commit 1a8642a

Please sign in to comment.