Skip to content

Commit d511ae5

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 49f0777 commit d511ae5

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
@@ -1974,17 +1974,49 @@ describe('$compile', function() {
19741974
));
19751975

19761976

1977-
it('should work when directive is in a repeater', inject(
1978-
function($compile, $httpBackend, $rootScope) {
1979-
$httpBackend.expect('GET', 'hello.html').
1977+
describe('when directive is in a repeater', function() {
1978+
var is;
1979+
beforeEach(function () {
1980+
is = [1, 2];
1981+
});
1982+
1983+
function runTest() {
1984+
inject(function ($compile, $httpBackend, $rootScope) {
1985+
$httpBackend.expect('GET', 'hello.html').
19801986
respond('<span>i=<span ng-transclude></span>;</span>');
1981-
element = jqLite('<div><b class=hello ng-repeat="i in [1,2]">{{i}}</b></div>');
1982-
$compile(element)($rootScope);
1987+
element = jqLite('<div><b class=hello ng-repeat="i in [' + is + ']">{{i}}</b></div>');
1988+
$compile(element)($rootScope);
19831989

1984-
$httpBackend.flush();
1985-
expect(element.text()).toEqual('i=1;i=2;');
1990+
$httpBackend.flush();
1991+
expect(element.text()).toEqual('i=' + is.join(';i=') + ';');
1992+
});
19861993
}
1987-
));
1994+
1995+
it('should work in jqLite and jQuery with jQuery.cleanData last patched by Angular', runTest);
1996+
1997+
if (jQuery) {
1998+
it('should work with another library patching jQuery.cleanData after Angular', function () {
1999+
var cleanedCount = 0;
2000+
var currentCleanData = jQuery.cleanData;
2001+
jQuery.cleanData = function (elems) {
2002+
cleanedCount += elems.length;
2003+
// Don't return the output and expicitly pass only the first parameter
2004+
// so that we're sure we're not relying on either of them. jQuery UI patch
2005+
// behaves in this way.
2006+
currentCleanData(elems);
2007+
};
2008+
2009+
runTest();
2010+
2011+
// The initial ng-repeat div is dumped after parsing hence we expect cleanData
2012+
// count to be one larger than size of the iterated array.
2013+
expect(cleanedCount).toBe(is.length + 1);
2014+
2015+
// Restore the previous jQuery.cleanData.
2016+
jQuery.cleanData = currentCleanData;
2017+
});
2018+
}
2019+
});
19882020

19892021

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

0 commit comments

Comments
 (0)