Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing for mouse wheel events

I've set up a simple function to handle mouse wheel events on a menu component I built. The component works fine, I'm trying to write a unit test around it and that is giving me an issue.

component handler:

handleWheel: function (event) {
        (event.deltaY < 0 ) ? this.moveUp() : this.moveDown();

        return false;
}

this.moveUp() / this.moveDown() simply sets the state of firstIndex

The issue is that when I try to write a test for this functionality I can't get it to work. I'm almost 100% certain it has to do with the eventDetails object i'm passing in, but I don't know how to format it correctly.

// set firstIndex = 0
TestUtils.Simulate.scroll(menu, {deltaY: 52});
expect(menu.state.firstIndex).to.equal(1);
// error: expected 0 to be 1

Does anyone know how to correctly format the TestUtils.Simulate.Scroll() / know of a better way to test onWheel() ?

like image 590
badAdviceGuy Avatar asked Nov 03 '14 15:11

badAdviceGuy


People also ask

How do I test my mouse scroll wheel?

Click and hold the middle button (press the scroll wheel down) of your mouse. The scroll wheel should turn blue on the picture. If you let go of the scroll wheel, the scroll wheel on the picture should stay light blue.

How do I know if my mouse wheel is working?

Hover your mouse pointer over the canvas and scroll in one direction as fast as you can. The program will draw a colored streamer moving to the right and also in the direction you're scrolling. As long as you don't change scrolling direction, the streamer should stay the same color.

What is scroll test?

Mouse Scroll Test, aka Roller Speed test or Scroll Speed Test, is a test to measure your scrolling speed. Have you ever wondered how many pixels you can scroll per second? Take this test now to find out. All you have to do is to scroll your mouse as fast as possible.


1 Answers

If the event handler is for onWheel you should use Simulate.wheel.

There's a 1:1 mapping of events to Simulate methods. Remove the "on" and lowercase the first letter.

onScroll   ->   Simulate.scroll
onKeyDown  ->   Simulate.keyDown
onWheel    ->   Simulate.wheel
like image 96
Brigand Avatar answered Nov 15 '22 08:11

Brigand