我是 QUnit 的新手。我正在使用 jQuery(用 1.4.2 和 1.5.1 测试)和最新的 QUnit。我可以在单个测试中很好地触发事件,但之后的任何测试都会失败。这是一个简化的重现:
// code under test - "#Test1" is just an empty div
$(document).ready(function() {
$('#Test1').mouseenter(function(e) { console.log('ENTER');});
$('#Test1').mouseleave(function(e) { console.log('LEAVE');});
});
// tests
test('enter', function() {
$('#Test1').mouseenter();
});
test('leave', function() {
$('#Test1').mouseleave();
});
当我运行测试时,控制台只输出 ENTER。但是,如果我使用单个测试...
test('enterleave', function() {
$('#Test1').mouseenter();
$('#Test1').mouseleave();
});
...控制台输出 ENTER 和 LEAVE。我试过使用 QUnit 的 triggerEvent、jQuery.trigger 等都无济于事。此问题在多个浏览器上重现。我是否正确地测试了事件?
完整重现:http: //jsbin.com/obehu5/edit。