Skip to content

Commit c306bc2

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 05791c0 commit c306bc2

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

test/ng/compileSpec.js

+38-8
Original file line numberDiff line numberDiff line change
@@ -1553,17 +1553,47 @@ describe('$compile', function() {
15531553
));
15541554

15551555

1556-
it('should work when directive is in a repeater', inject(
1557-
function($compile, $httpBackend, $rootScope) {
1558-
$httpBackend.expect('GET', 'hello.html').
1556+
describe('when directive is in a repeater', function() {
1557+
var is;
1558+
beforeEach(function () {
1559+
is = [1, 2];
1560+
});
1561+
1562+
function runTest() {
1563+
inject(function ($compile, $httpBackend, $rootScope) {
1564+
$httpBackend.expect('GET', 'hello.html').
15591565
respond('<span>i=<span ng-transclude></span>;</span>');
1560-
element = jqLite('<div><b class=hello ng-repeat="i in [1,2]">{{i}}</b></div>');
1561-
$compile(element)($rootScope);
1566+
element = jqLite('<div><b class=hello ng-repeat="i in [' + is + ']">{{i}}</b></div>');
1567+
$compile(element)($rootScope);
15621568

1563-
$httpBackend.flush();
1564-
expect(element.text()).toEqual('i=1;i=2;');
1569+
$httpBackend.flush();
1570+
expect(element.text()).toEqual('i=' + is.join(';i=') + ';');
1571+
});
15651572
}
1566-
));
1573+
1574+
it('should work in jqLite and jQuery with jQuery.cleanData last patched by Angular', runTest);
1575+
1576+
it('should work with another library patching jQuery.cleanData after Angular', function() {
1577+
var cleanedCount = 0;
1578+
var currentCleanData = jQuery.cleanData;
1579+
jQuery.cleanData = function (elems) {
1580+
cleanedCount += elems.length;
1581+
// Don't return the output and expicitly pass only the first parameter
1582+
// so that we're sure we're not relying on either of them. jQuery UI patch
1583+
// behaves in this way.
1584+
currentCleanData(elems);
1585+
};
1586+
1587+
runTest();
1588+
1589+
// The initial ng-repeat div is dumped after parsing hence we expect cleanData
1590+
// count to be one larger than size of the iterated array.
1591+
expect(cleanedCount).toBe(is.length + 1);
1592+
1593+
// Restore the previous jQuery.cleanData.
1594+
jQuery.cleanData = currentCleanData;
1595+
});
1596+
});
15671597

15681598

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

0 commit comments

Comments
 (0)