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

Commit c25cb7d

Browse files
committed
refactor(formSpec): group preventDefault specs into a describe
1 parent 54e4a6f commit c25cb7d

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

test/ng/directive/formSpec.js

+33-30
Original file line numberDiff line numberDiff line change
@@ -64,36 +64,6 @@ describe('form', function() {
6464
});
6565

6666

67-
it('should prevent form submission', function() {
68-
var startingUrl = '' + window.location;
69-
doc = jqLite('<form name="myForm"><input type="submit" value="submit" />');
70-
$compile(doc)(scope);
71-
72-
browserTrigger(doc.find('input'));
73-
waitsFor(
74-
function() { return true; },
75-
'let browser breath, so that the form submision can manifest itself', 10);
76-
77-
runs(function() {
78-
expect('' + window.location).toEqual(startingUrl);
79-
});
80-
});
81-
82-
83-
it('should not prevent form submission if action attribute present', function() {
84-
var callback = jasmine.createSpy('submit').andCallFake(function(event) {
85-
expect(event.isDefaultPrevented()).toBe(false);
86-
event.preventDefault();
87-
});
88-
89-
doc = $compile('<form name="x" action="some.py" />')(scope);
90-
doc.bind('submit', callback);
91-
92-
browserTrigger(doc, 'submit');
93-
expect(callback).toHaveBeenCalledOnce();
94-
});
95-
96-
9767
it('should publish form to scope when name attr is defined', function() {
9868
doc = $compile('<form name="myForm"></form>')(scope);
9969
expect(scope.myForm).toBeTruthy();
@@ -155,6 +125,39 @@ describe('form', function() {
155125
});
156126

157127

128+
describe('preventing default submission', function() {
129+
130+
it('should prevent form submission', function() {
131+
var startingUrl = '' + window.location;
132+
doc = jqLite('<form name="myForm"><input type="submit" value="submit" />');
133+
$compile(doc)(scope);
134+
135+
browserTrigger(doc.find('input'));
136+
waitsFor(
137+
function() { return true; },
138+
'let browser breath, so that the form submission can manifest itself', 10);
139+
140+
runs(function() {
141+
expect('' + window.location).toEqual(startingUrl);
142+
});
143+
});
144+
145+
146+
it('should not prevent form submission if action attribute present', function() {
147+
var callback = jasmine.createSpy('submit').andCallFake(function(event) {
148+
expect(event.isDefaultPrevented()).toBe(false);
149+
event.preventDefault();
150+
});
151+
152+
doc = $compile('<form name="x" action="some.py" />')(scope);
153+
doc.bind('submit', callback);
154+
155+
browserTrigger(doc, 'submit');
156+
expect(callback).toHaveBeenCalledOnce();
157+
});
158+
});
159+
160+
158161
describe('nested forms', function() {
159162

160163
it('should chain nested forms', function() {

0 commit comments

Comments
 (0)