mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-20 04:11:51 +00:00
fix(mocks): free up memory after every spec
This commit is contained in:
parent
8114d55a15
commit
1a8642aac2
1 changed files with 25 additions and 3 deletions
28
src/ngMock/angular-mocks.js
vendored
28
src/ngMock/angular-mocks.js
vendored
|
|
@ -1591,9 +1591,29 @@ window.jasmine && (function(window) {
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
var spec = getCurrentSpec();
|
var spec = getCurrentSpec();
|
||||||
|
var injector = spec.$injector;
|
||||||
|
|
||||||
spec.$injector = null;
|
spec.$injector = null;
|
||||||
spec.$modules = null;
|
spec.$modules = null;
|
||||||
|
|
||||||
|
if (injector) {
|
||||||
|
injector.get('$rootElement').unbind();
|
||||||
|
injector.get('$browser').pollFns.length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
angular.mock.clearDataCache();
|
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() {
|
function getCurrentSpec() {
|
||||||
|
|
@ -1694,7 +1714,7 @@ window.jasmine && (function(window) {
|
||||||
*/
|
*/
|
||||||
window.inject = angular.mock.inject = function() {
|
window.inject = angular.mock.inject = function() {
|
||||||
var blockFns = Array.prototype.slice.call(arguments, 0);
|
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;
|
return isSpecRunning() ? workFn() : workFn;
|
||||||
/////////////////////
|
/////////////////////
|
||||||
function workFn() {
|
function workFn() {
|
||||||
|
|
@ -1710,10 +1730,12 @@ window.jasmine && (function(window) {
|
||||||
try {
|
try {
|
||||||
injector.invoke(blockFns[i] || angular.noop, this);
|
injector.invoke(blockFns[i] || angular.noop, this);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if(e.stack) e.stack += '\n' + stack;
|
if(e.stack) e.stack += '\n' + errorForStack.stack;
|
||||||
throw e;
|
throw e;
|
||||||
|
} finally {
|
||||||
|
errorForStack = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
})(window);
|
})(window);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue