Skip to content

Commit

Permalink
Ignore any events that bubble up to the document while testing.
Browse files Browse the repository at this point in the history
Avoids triggering the browser's built-in "middle click to scroll" behavior when running specs.
  • Loading branch information
shunter committed Dec 8, 2014
1 parent 8749f60 commit f1586a6
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Specs/Core/ScreenSpaceEventHandlerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,20 @@ defineSuite([
return cloningSpy;
}

var eventsToStop = 'pointerdown pointerup pointermove mousedown mouseup mousemove touchstart touchend touchmove dblclick wheel mousewheel DOMMouseScroll'.split(' ');

function stop(event) {
event.stopPropagation();
event.preventDefault();
}

beforeEach(function() {
// ignore events that bubble up to the document.
// this prevents triggering the browser's "middle click to scroll" behavior
eventsToStop.forEach(function(e) {
document.addEventListener(e, stop, false);
});

element = document.createElement('div');
element.style.position = 'absolute';
element.style.top = '0';
Expand All @@ -74,6 +87,10 @@ defineSuite([
afterEach(function() {
document.body.removeChild(element);
handler = !handler.isDestroyed() && handler.destroy();

eventsToStop.forEach(function(e) {
document.removeEventListener(e, stop, false);
});
});

describe('setInputAction', function() {
Expand Down

0 comments on commit f1586a6

Please sign in to comment.