From b8fefb71753aad2bd7c6766e2009ba7c166e2fce Mon Sep 17 00:00:00 2001 From: jankuca Date: Thu, 3 Oct 2013 15:49:26 -0700 Subject: [PATCH] feat(jQuery): upgrade to jQuery 2.0 [WIP] jQuery 2.0 removes `jQuery.cache` which prevents the angular-mocks logic to clean up after each test (to remove element data). There are two tests that fail because of this change. One way to fix this might be monkey-patching `jQuery#data` with a proxy which would keep track of all elements and data that need to be cleaned. --- src/Angular.js | 1 + src/ng/compile.js | 5 +++++ test/ng/compileSpec.js | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Angular.js b/src/Angular.js index ad281504bf3c..29c9c762541b 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -1160,6 +1160,7 @@ function bindJQuery() { JQLitePatchJQueryRemove('remove', true, true, false); JQLitePatchJQueryRemove('empty', false, false, false); JQLitePatchJQueryRemove('html', false, false, true); + JQLitePatchJQueryRemove('replaceWith', true, false, false); } else { jqLite = JQLite; } diff --git a/src/ng/compile.js b/src/ng/compile.js index 2b70abfc2f67..f84e97a68452 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -1370,6 +1370,7 @@ function $CompileProvider($provide) { var firstElementToRemove = elementsToRemove[0], removeCount = elementsToRemove.length, parent = firstElementToRemove.parentNode, + scope = jQuery(firstElementToRemove).data('$scope'), i, ii; if ($rootElement) { @@ -1404,6 +1405,10 @@ function $CompileProvider($provide) { delete elementsToRemove[k]; } + if (scope) { + jQuery(newNode).data('$scope', scope); + } + elementsToRemove[0] = newNode; elementsToRemove.length = 1 } diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 1e66b49fa924..4cfb6372d775 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -3256,7 +3256,7 @@ describe('$compile', function() { $rootScope.dataOnVar = 'data-on text'; $rootScope.$apply(); expect(element.attr('data-on')).toEqual('data-on text'); - + element = $compile('