aboutsummaryrefslogtreecommitdiffstats
path: root/test/ng/directive/formSpec.js
diff options
context:
space:
mode:
authorIgor Minar2012-08-07 22:03:02 -0700
committerIgor Minar2012-08-07 22:07:49 -0700
commit5cec32492c52209ce11b38b8180f9bdb909d041b (patch)
treec9c79844f3978c7598bcf356d8590659ba414172 /test/ng/directive/formSpec.js
parentc25cb7d48872fbb37b68f57c9c493ed8bb86a140 (diff)
downloadangular.js-5cec32492c52209ce11b38b8180f9bdb909d041b.tar.bz2
test(form): fix broken preventDefault test
the original test relied on incorrect assumptions about how jasmine async tests work (when setTimeout is triggered) and how browser reloads a page (the sequence of events) and thus the test passes even when the default is not prevented. this change fixes the test by registering an extra submit event handler that checks if the default was prevented. if the default was not prevented, the test will fail and the page will be reloaded causing the test runner to panic.
Diffstat (limited to 'test/ng/directive/formSpec.js')
-rw-r--r--test/ng/directive/formSpec.js20
1 files changed, 14 insertions, 6 deletions
diff --git a/test/ng/directive/formSpec.js b/test/ng/directive/formSpec.js
index fa047480..96855f52 100644
--- a/test/ng/directive/formSpec.js
+++ b/test/ng/directive/formSpec.js
@@ -128,17 +128,25 @@ describe('form', function() {
describe('preventing default submission', function() {
it('should prevent form submission', function() {
- var startingUrl = '' + window.location;
- doc = jqLite('<form name="myForm"><input type="submit" value="submit" />');
+ var nextTurn = false,
+ reloadPrevented;
+
+ doc = jqLite('<form><input type="submit" value="submit" ></form>');
$compile(doc)(scope);
+ doc.bind('submit', function(e) {
+ reloadPrevented = e.defaultPrevented;
+ });
+
browserTrigger(doc.find('input'));
- waitsFor(
- function() { return true; },
- 'let browser breath, so that the form submission can manifest itself', 10);
+
+ // let the browser process all events (and potentially reload the page)
+ setTimeout(function() { nextTurn = true;});
+
+ waitsFor(function() { return nextTurn; });
runs(function() {
- expect('' + window.location).toEqual(startingUrl);
+ expect(reloadPrevented).toBe(true);
});
});