From 811af9ccfbc973117926c052232d65165dc5f576 Mon Sep 17 00:00:00 2001 From: Georgios Kalpakas Date: Wed, 2 Aug 2017 14:43:10 +0300 Subject: [PATCH] test(*): fix tests involving `submit` on Chrome 60 On Chrome 60 (at least on Windows) the `submit` event when clicking on a submit button is not fired on the form element, unless it is already part of the DOM. --- test/ng/directive/formSpec.js | 16 ++++++++++++++-- test/ng/directive/ngEventDirsSpec.js | 22 ++++++++++++++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/test/ng/directive/formSpec.js b/test/ng/directive/formSpec.js index e1d681956b23..b48ff1084468 100644 --- a/test/ng/directive/formSpec.js +++ b/test/ng/directive/formSpec.js @@ -386,6 +386,9 @@ describe('form', function() { doc = jqLite('
' + '' + '
'); + // Support: Chrome 60+ (on Windows) + // We need to add the form to the DOM in order for `submit` events to be properly fired. + window.document.body.appendChild(doc[0]); var assertPreventDefaultListener = function(e) { reloadPrevented = e.defaultPrevented || (e.returnValue === false); @@ -420,15 +423,18 @@ describe('form', function() { inject(function($timeout) { doc = jqLite('
' + '
' + - '' + + '' + '
' + '
'); + // Support: Chrome 60+ (on Windows) + // We need to add the form to the DOM in order for `submit` events to be properly fired. + window.document.body.appendChild(doc[0]); var form = doc.find('form'), destroyed = false, nextTurn = false, submitted = false, - reloadPrevented; + reloadPrevented = 'never called'; scope.destroy = function() { // yes, I know, scope methods should not do direct DOM manipulation, but I wanted to keep @@ -466,6 +472,12 @@ describe('form', function() { // the issue in the wild, I'm not going to bother to do it // now. (i) + // Support: Chrome 60+ (on Windows) + // Chrome 60+ on Windows does not fire `submit` events when the form is not attached to + // the DOM. Verify that the `submit` listener was either never fired or (if fired) the + // reload was prevented. + expect(reloadPrevented).not.toBe(false); + // prevent mem leak in test form[0].removeEventListener('submit', assertPreventDefaultListener); }) diff --git a/test/ng/directive/ngEventDirsSpec.js b/test/ng/directive/ngEventDirsSpec.js index d8288b828bbd..5555c592df6d 100644 --- a/test/ng/directive/ngEventDirsSpec.js +++ b/test/ng/directive/ngEventDirsSpec.js @@ -12,15 +12,20 @@ describe('event directives', function() { describe('ngSubmit', function() { it('should get called on form submit', inject(function($rootScope, $compile) { - element = $compile('
' + - '' + + element = $compile( + '' + + '' + '
')($rootScope); $rootScope.$digest(); + // Support: Chrome 60+ + // We need to add the form to the DOM in order for `submit` events to be properly fired. + window.document.body.appendChild(element[0]); + // prevent submit within the test harness element.on('submit', function(e) { e.preventDefault(); }); - expect($rootScope.submitted).not.toBeDefined(); + expect($rootScope.submitted).toBeUndefined(); browserTrigger(element.children()[0]); expect($rootScope.submitted).toEqual(true); @@ -33,15 +38,20 @@ describe('event directives', function() { } }; - element = $compile('
' + - '' + + element = $compile( + '' + + '' + '
')($rootScope); $rootScope.$digest(); + // Support: Chrome 60+ (on Windows) + // We need to add the form to the DOM in order for `submit` events to be properly fired. + window.document.body.appendChild(element[0]); + // prevent submit within the test harness element.on('submit', function(e) { e.preventDefault(); }); - expect($rootScope.formSubmitted).not.toBeDefined(); + expect($rootScope.formSubmitted).toBeUndefined(); browserTrigger(element.children()[0]); expect($rootScope.formSubmitted).toEqual('foo');