Qunit Example
Regular expression testing with qunit
HTML
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.12.0.css">
<script src="http://code.jquery.com/qunit/qunit-1.12.0.js"></script>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<input id="text1" />
<input id="text2" />
<input id="text3" />
<br/>
JavaScript
test("$.on(types)", function () {
var expected = ["keyup", "blur", "focusout"],
result = [];
jQuery("#text1").on({
focus: function () {
result.push("keyup");
jQuery("#text1").blur();
},
blur: function () {
result.push("blur");
},
focusout: function () {
result.push("focusout");
}
});
jQuery("#text1").triggerHandler( "focus" )
deepEqual(result, expected, "triggerHandler correctly triggering focus");
});
test("$.event(fn)", function () {
expect(1);
var expected = ["keyup", "blur", "focusout"],
result2 = [];
jQuery("#text2").focus(function () {
result2.push("keyup");
jQuery("#text2").blur();
});
jQuery("#text2 ").blur(function () {
result2.push("blur");
});
jQuery("#text2").focusout(function () {
result2.push("focusout");
});
jQuery("#text2").triggerHandler( "focus" )
deepEqual(result2, expected, "triggerHandler correctly triggering focus");
});
test("$.on(types, selector)", function () {
expect(1);
var expected = ["keyup", "blur", "focusout"],
result3 = [];
jQuery("body").on({
focus: function () {
result3.push("keyup");
jQuery("#text3").blur();
},
blur: function () {
result3.push("blur");
},
focusout: function () {
result3.push("focusout");
}
}, "#text3");
jQuery("#text3").triggerHandler( "focus" )
deepEqual(result3, expected, "triggerHandler correctly triggering focus");
});