Skip to content

Commit 92ee896

Browse files
committed
test(jQuery): test not firing $destroy on jQuery.cleanData with jQuery UI
So far it wasn't tested that Angular's logic for skipping it triggering the $destroy event on jQuery.cleanData in the replaceWith internal function works correctly when Angular is not the last one to patch the cleanData method (e.g. if jQuery UI does the patching later). This commits adds the relevant test. Ref angular#8486
1 parent 74a214c commit 92ee896

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

test/ng/compileSpec.js

+40-8
Original file line numberDiff line numberDiff line change
@@ -1756,17 +1756,49 @@ describe('$compile', function() {
17561756
));
17571757

17581758

1759-
it('should work when directive is in a repeater', inject(
1760-
function($compile, $httpBackend, $rootScope) {
1761-
$httpBackend.expect('GET', 'hello.html').
1759+
describe('when directive is in a repeater', function() {
1760+
var is;
1761+
beforeEach(function () {
1762+
is = [1, 2];
1763+
});
1764+
1765+
function runTest() {
1766+
inject(function ($compile, $httpBackend, $rootScope) {
1767+
$httpBackend.expect('GET', 'hello.html').
17621768
respond('<span>i=<span ng-transclude></span>;</span>');
1763-
element = jqLite('<div><b class=hello ng-repeat="i in [1,2]">{{i}}</b></div>');
1764-
$compile(element)($rootScope);
1769+
element = jqLite('<div><b class=hello ng-repeat="i in [' + is + ']">{{i}}</b></div>');
1770+
$compile(element)($rootScope);
17651771

1766-
$httpBackend.flush();
1767-
expect(element.text()).toEqual('i=1;i=2;');
1772+
$httpBackend.flush();
1773+
expect(element.text()).toEqual('i=' + is.join(';i=') + ';');
1774+
});
17681775
}
1769-
));
1776+
1777+
it('should work in jqLite and jQuery with jQuery.cleanData last patched by Angular', runTest);
1778+
1779+
if (jQuery) {
1780+
it('should work with another library patching jQuery.cleanData after Angular', function () {
1781+
var cleanedCount = 0;
1782+
var currentCleanData = jQuery.cleanData;
1783+
jQuery.cleanData = function (elems) {
1784+
cleanedCount += elems.length;
1785+
// Don't return the output and expicitly pass only the first parameter
1786+
// so that we're sure we're not relying on either of them. jQuery UI patch
1787+
// behaves in this way.
1788+
currentCleanData(elems);
1789+
};
1790+
1791+
runTest();
1792+
1793+
// The initial ng-repeat div is dumped after parsing hence we expect cleanData
1794+
// count to be one larger than size of the iterated array.
1795+
expect(cleanedCount).toBe(is.length + 1);
1796+
1797+
// Restore the previous jQuery.cleanData.
1798+
jQuery.cleanData = currentCleanData;
1799+
});
1800+
}
1801+
});
17701802

17711803

17721804
it("should fail if replacing and template doesn't have a single root element", function() {

0 commit comments

Comments
 (0)