aboutsummaryrefslogtreecommitdiffstats
path: root/test/jQueryPatchSpec.js
diff options
context:
space:
mode:
authorMichał Gołębiowski2013-04-30 11:29:07 +0200
committerVojta Jina2013-05-23 12:05:55 -0700
commitda5f537ccdb0a7b4155f13f7a70ca7981ad6f689 (patch)
tree30fc4349dc22289d110f1bfdea0db076121a89c0 /test/jQueryPatchSpec.js
parent041f118b01933fa07098f1333be8e2cf1a28f248 (diff)
downloadangular.js-da5f537ccdb0a7b4155f13f7a70ca7981ad6f689.tar.bz2
fix(jqLite): correctly monkey-patch core jQuery methods
When real jQuery is present, Angular monkey patch it to fire `$destroy` event. This commit fixes two issues in the jQuery patch: - passing a selector to the $.fn.remove method (only fire `$destroy` on the matched elements) - using `$.fn.html` without parameters as a getter (do not fire `$destroy`)
Diffstat (limited to 'test/jQueryPatchSpec.js')
-rw-r--r--test/jQueryPatchSpec.js48
1 files changed, 47 insertions, 1 deletions
diff --git a/test/jQueryPatchSpec.js b/test/jQueryPatchSpec.js
index 19f4d821..0680a0c3 100644
--- a/test/jQueryPatchSpec.js
+++ b/test/jQueryPatchSpec.js
@@ -49,9 +49,55 @@ if (window.jQuery) {
doc.empty();
});
- it('should fire on html()', function() {
+ it('should fire on html(param)', function() {
doc.html('abc');
});
+
+ it('should fire on html(\'\')', function() {
+ doc.html('');
+ });
+ });
+ });
+
+ describe('jQuery patch eagerness', function() {
+
+ var doc = null;
+ var divSpy = null;
+ var spy1 = null;
+ var spy2 = null;
+
+ beforeEach(function() {
+ divSpy = jasmine.createSpy('div.$destroy');
+ spy1 = jasmine.createSpy('span1.$destroy');
+ spy2 = jasmine.createSpy('span2.$destroy');
+ doc = $('<div><span class=first>abc</span><span class=second>xyz</span></div>');
+ doc.find('span.first').bind('$destroy', spy1);
+ doc.find('span.second').bind('$destroy', spy2);
+ });
+
+ afterEach(function() {
+ expect(divSpy).not.toHaveBeenCalled();
+ expect(spy1).not.toHaveBeenCalled();
+ });
+
+ describe('$detach event is not invoked in too many cases', function() {
+
+ it('should fire only on matched elements on detach(selector)', function() {
+ doc.find('span').detach('.second');
+ expect(spy2).toHaveBeenCalled();
+ expect(spy2.callCount).toEqual(1);
+ });
+
+ it('should fire only on matched elements on remove(selector)', function() {
+ doc.find('span').remove('.second');
+ expect(spy2).toHaveBeenCalled();
+ expect(spy2.callCount).toEqual(1);
+ });
+
+ it('should not fire on html()', function() {
+ doc.html();
+ expect(spy2).not.toHaveBeenCalled();
+ });
});
});
}