Javascript 使用Mock.Interactions模拟鼠标在聚合物元素上编写单元测试
我正在为自定义聚合物元素编写单元测试,需要模拟鼠标悬停事件,并检查鼠标悬停时是否显示按钮(隐藏) 我正在使用铁测试助手(模拟交互)。在测试期间,我收到以下错误消息: 错误:MockInteractions.mouseover不是函数 我的问题是我找不到合适的函数(Javascript 使用Mock.Interactions模拟鼠标在聚合物元素上编写单元测试,javascript,unit-testing,polymer,polymer-1.0,Javascript,Unit Testing,Polymer,Polymer 1.0,我正在为自定义聚合物元素编写单元测试,需要模拟鼠标悬停事件,并检查鼠标悬停时是否显示按钮(隐藏) 我正在使用铁测试助手(模拟交互)。在测试期间,我收到以下错误消息: 错误:MockInteractions.mouseover不是函数 我的问题是我找不到合适的函数(.hover,mouseOver和类似的组合都不起作用),也不确定在Mock.Interactions中是否没有合适的函数,或者我就是找不到合适的函数 我的代码(仅测试部分): Hi mouseover是HTML元素的一个事件,当鼠标指
.hover
,mouseOver
和类似的组合都不起作用),也不确定在Mock.Interactions
中是否没有合适的函数,或者我就是找不到合适的函数
我的代码(仅测试部分):
Hi mouseover是HTML元素的一个事件,当鼠标指针指向某个元素时会触发该事件。这不是一个鼠标可以做的交互。因此,您实际上要做的是一个鼠标移动事件来触发mouseover事件
test('check settings btb shows on hover', function(done) {
var hoverSpy = sinon.spy();
var button = Polymer.dom(myEl5.root).querySelector('#user-settings');
button.addEventListener('mouseover', hoverSpy);
MockInteractions.move(button, {x: 0, y: 0},
{
x: button.offsetLeft + (button.offsetWidth / 2),
y: button.offsetTop + (button.offsetHeight / 2)
});
});
});
这段代码应该模拟将鼠标移动到按钮的中心
test('check settings btb shows on hover', function(done) {
var hoverSpy = sinon.spy();
var button = Polymer.dom(myEl5.root).querySelector('#user-settings');
button.addEventListener('mouseover', hoverSpy);
MockInteractions.move(button, {x: 0, y: 0},
{
x: button.offsetLeft + (button.offsetWidth / 2),
y: button.offsetTop + (button.offsetHeight / 2)
});
});
});