Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit ed581ec

Browse files
committed
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.
1 parent 3650723 commit ed581ec

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

test/ng/directive/formSpec.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,9 @@ describe('form', function() {
386386
doc = jqLite('<form ng-submit="submitMe()">' +
387387
'<input type="submit" value="submit">' +
388388
'</form>');
389+
// Support: Chrome 60+ (on Windows)
390+
// We need to add the form to the DOM in order for `submit` events to be properly fired.
391+
window.document.body.appendChild(doc[0]);
389392

390393
var assertPreventDefaultListener = function(e) {
391394
reloadPrevented = e.defaultPrevented || (e.returnValue === false);
@@ -420,15 +423,18 @@ describe('form', function() {
420423
inject(function($timeout) {
421424
doc = jqLite('<div>' +
422425
'<form ng-submit="submitMe()">' +
423-
'<button ng-click="destroy()"></button>' +
426+
'<button type="submit" ng-click="destroy()"></button>' +
424427
'</form>' +
425428
'</div>');
429+
// Support: Chrome 60+ (on Windows)
430+
// We need to add the form to the DOM in order for `submit` events to be properly fired.
431+
window.document.body.appendChild(doc[0]);
426432

427433
var form = doc.find('form'),
428434
destroyed = false,
429435
nextTurn = false,
430436
submitted = false,
431-
reloadPrevented;
437+
reloadPrevented = 'never called';
432438

433439
scope.destroy = function() {
434440
// yes, I know, scope methods should not do direct DOM manipulation, but I wanted to keep
@@ -460,6 +466,7 @@ describe('form', function() {
460466
.runs(function() {
461467
expect(doc.html()).toBe('');
462468
expect(destroyed).toBe(true);
469+
expect(reloadPrevented).toBe('never called');
463470
expect(submitted).toBe(false); // this is known corner-case that is not currently handled
464471
// the issue is that the submit listener is destroyed before
465472
// the event propagates there. we can fix this if we see

test/ng/directive/ngEventDirsSpec.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,20 @@ describe('event directives', function() {
1212
describe('ngSubmit', function() {
1313

1414
it('should get called on form submit', inject(function($rootScope, $compile) {
15-
element = $compile('<form action="/foo" ng-submit="submitted = true">' +
16-
'<input type="submit"/>' +
15+
element = $compile(
16+
'<form action="/foo" ng-submit="submitted = true">' +
17+
'<input type="submit" />' +
1718
'</form>')($rootScope);
1819
$rootScope.$digest();
1920

21+
// Support: Chrome 60+
22+
// We need to add the form to the DOM in order for `submit` events to be properly fired.
23+
window.document.body.appendChild(element[0]);
24+
2025
// prevent submit within the test harness
2126
element.on('submit', function(e) { e.preventDefault(); });
2227

23-
expect($rootScope.submitted).not.toBeDefined();
28+
expect($rootScope.submitted).toBeUndefined();
2429

2530
browserTrigger(element.children()[0]);
2631
expect($rootScope.submitted).toEqual(true);
@@ -33,15 +38,20 @@ describe('event directives', function() {
3338
}
3439
};
3540

36-
element = $compile('<form action="/foo" ng-submit="formSubmission($event)">' +
37-
'<input type="submit"/>' +
41+
element = $compile(
42+
'<form action="/foo" ng-submit="formSubmission($event)">' +
43+
'<input type="submit" />' +
3844
'</form>')($rootScope);
3945
$rootScope.$digest();
4046

47+
// Support: Chrome 60+ (on Windows)
48+
// We need to add the form to the DOM in order for `submit` events to be properly fired.
49+
window.document.body.appendChild(element[0]);
50+
4151
// prevent submit within the test harness
4252
element.on('submit', function(e) { e.preventDefault(); });
4353

44-
expect($rootScope.formSubmitted).not.toBeDefined();
54+
expect($rootScope.formSubmitted).toBeUndefined();
4555

4656
browserTrigger(element.children()[0]);
4757
expect($rootScope.formSubmitted).toEqual('foo');

0 commit comments

Comments
 (0)