From c91f99cfa96d1419ac4e3f69263d2c98a823bea2 Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Wed, 11 Sep 2013 16:07:34 -0700 Subject: [PATCH] Fix test race condition with DOMContentLoaded Test tap could somtimes fire before the event handlers were added --- tests/tap.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/tap.js b/tests/tap.js index 5a50d4a..20cf033 100644 --- a/tests/tap.js +++ b/tests/tap.js @@ -1,7 +1,15 @@ suite('Tap', function() { test('Up and Down', function(done) { prepare(target, 'tap', done); - target.dispatchEvent(new PointerEvent('pointerdown', {isPrimary: true, buttons: 1, pointerId: 1, bubbles: true})); - target.dispatchEvent(new PointerEvent('pointerup', {isPrimary: true, buttons: 1, pointerId: 1, bubbles: true})); + var fireTap = function() { + target.dispatchEvent(new PointerEvent('pointerdown', {isPrimary: true, buttons: 1, pointerId: 1, bubbles: true})); + target.dispatchEvent(new PointerEvent('pointerup', {isPrimary: true, buttons: 1, pointerId: 1, bubbles: true})); + } + // handle case where DOMContentLoaded has already fired + if (document.readyState === 'complete') { + fireTap(); + } else { + document.addEventListener('DOMContentLoaded', fireTap); + } }); });