aboutsummaryrefslogtreecommitdiffstats
path: root/test/jqLiteSpec.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/jqLiteSpec.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/jqLiteSpec.js')
-rw-r--r--test/jqLiteSpec.js30
1 files changed, 28 insertions, 2 deletions
diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js
index f159e08f..406b7a5a 100644
--- a/test/jqLiteSpec.js
+++ b/test/jqLiteSpec.js
@@ -291,11 +291,37 @@ describe('jqLite', function() {
expect(element.data()).toEqual({meLike: 'turtles', youLike: 'carrots', existing: 'val'});
expect(element.data()).toBe(oldData); // merge into the old object
});
+
+ describe('data cleanup', function() {
+ it('should remove data on element removal', function() {
+ var div = jqLite('<div><span>text</span></div>'),
+ span = div.find('span');
+
+ span.data('name', 'angular');
+ span.remove();
+ expect(span.data('name')).toBeUndefined();
+ });
+
+ it('should remove event listeners on element removal', function() {
+ var div = jqLite('<div><span>text</span></div>'),
+ span = div.find('span'),
+ log = '';
+
+ span.bind('click', function() { log+= 'click;'});
+ browserTrigger(span);
+ expect(log).toEqual('click;');
+
+ span.remove();
+
+ browserTrigger(span);
+ expect(log).toEqual('click;');
+ });
+ });
});
describe('attr', function() {
- it('shoul read write and remove attr', function() {
+ it('should read write and remove attr', function() {
var selector = jqLite([a, b]);
expect(selector.attr('prop', 'value')).toEqual(selector);
@@ -667,7 +693,7 @@ describe('jqLite', function() {
var jWindow = jqLite(window).bind('hashchange', function() {
log = 'works!';
});
- eventFn({});
+ eventFn({type: 'hashchange'});
expect(log).toEqual('works!');
dealoc(jWindow);
});