aboutsummaryrefslogtreecommitdiffstats
path: root/test/ngMock/angular-mocksSpec.js
diff options
context:
space:
mode:
authorMisko Hevery2012-05-09 19:27:15 -0400
committerIgor Minar2012-05-14 21:56:22 -0700
commitec1c5dfaee32f9638cedd28bb96bbbecce9d0cf0 (patch)
tree13272649b7df2eb8e9f0d629df527983d66c5d57 /test/ngMock/angular-mocksSpec.js
parent24e7da4f1954dbe2e89f82950ed00292678534fd (diff)
downloadangular.js-ec1c5dfaee32f9638cedd28bb96bbbecce9d0cf0.tar.bz2
fix(jqLite): .data()/.bind() memory leak
Since angular attaches scope/injector/controller into DOM it should clean up after itself. No need to complain about memory leaks, since they can only happened on detached DOM. Detached DOM would only be in tests, since in production the DOM would be attached to render tree and removal would automatically clear memory.
Diffstat (limited to 'test/ngMock/angular-mocksSpec.js')
-rw-r--r--test/ngMock/angular-mocksSpec.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/ngMock/angular-mocksSpec.js b/test/ngMock/angular-mocksSpec.js
index 22c91a4d..88946ab9 100644
--- a/test/ngMock/angular-mocksSpec.js
+++ b/test/ngMock/angular-mocksSpec.js
@@ -148,6 +148,7 @@ describe('ngMock', function() {
});
});
+
describe('$log', function() {
var $log;
beforeEach(inject(['$log', function(log) {
@@ -229,6 +230,7 @@ describe('ngMock', function() {
});
});
+
describe('defer', function() {
var browser, log;
beforeEach(inject(function($browser) {
@@ -341,6 +343,44 @@ describe('ngMock', function() {
});
});
+
+ describe('angular.mock.clearDataCache', function() {
+ function keys(obj) {
+ var keys = [];
+ for(var key in obj) {
+ if (obj.hasOwnProperty(key)) keys.push(key);
+ }
+ return keys.sort();
+ }
+
+ it('should remove data', function() {
+ expect(angular.element.cache).toEqual({});
+ var div = angular.element('<div></div>');
+ div.data('name', 'angular');
+ expect(keys(angular.element.cache)).not.toEqual([]);
+ angular.mock.clearDataCache();
+ expect(keys(angular.element.cache)).toEqual([]);
+ });
+
+ it('should deregister event handlers', function() {
+ expect(keys(angular.element.cache)).toEqual([]);
+
+ var div = angular.element('<div></div>');
+
+ div.bind('click', angular.noop);
+ div.bind('mousemove', angular.noop);
+ div.data('some', 'data');
+ expect(keys(angular.element.cache).length).toBe(1);
+
+ angular.mock.clearDataCache();
+ expect(keys(angular.element.cache)).toEqual([]);
+ expect(div.data('some')).toBeUndefined();
+
+ div.remove();
+ });
+ });
+
+
describe('jasmine module and inject', function(){
var log;