测试鼠标滚轮事件 [英] Testing for mouse wheel events

查看:91
本文介绍了测试鼠标滚轮事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一个简单的函数来处理我构建的菜单组件上的鼠标滚轮事件.该组件工作正常,我正在尝试围绕它编写一个单元测试,这给了我一个问题.

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.

组件处理程序:

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

        return false;
}

this.moveUp()/this.moveDown()只需设置firstIndex

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

问题在于,当我尝试为此功能编写测试时,无法正常工作.我几乎100%确信它与我传入的eventDetails对象有关,但是我不知道如何正确格式化它.

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

有人知道如何正确格式化TestUtils.Simulate.Scroll()/了解测试onWheel()的更好方法吗?

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

推荐答案

如果事件处理程序用于onWheel,则应使用Simulate.wheel.

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

事件与模拟方法之间存在1:1的映射.删除开"并小写第一个字母.

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

这篇关于测试鼠标滚轮事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆