Testing mouse wheel events

I created a simple function to handle mouse wheel events in the menu component that I built. The component works fine, I'm trying to write a unit test around it, and this causes me a problem.

component handler:

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

this.moveUp () / this.moveDown () just sets the state to firstIndex

The problem is that when I try to write a test for this function, I cannot get it to work. I am almost 100% sure that it is associated with the eventDetails object that I am transitioning to, but I do not 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 format TestUtils.Simulate.Scroll () correctly / know the best way to test onWheel ()?

+6
source share
1 answer

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

There is a 1: 1 event mapping for simulating methods. Remove "on" and enter a lowercase letter.

 onScroll -> Simulate.scroll onKeyDown -> Simulate.keyDown onWheel -> Simulate.wheel 
+8
source

Source: https://habr.com/ru/post/977661/


All Articles