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

Commit

Permalink
test(form): fix broken preventDefault test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
IgorMinar committed Aug 8, 2012
1 parent c25cb7d commit 5cec324
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions test/ng/directive/formSpec.js
Expand Up @@ -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);
});
});

Expand Down

0 comments on commit 5cec324

Please sign in to comment.