Qunit Example
Regular expression testing with qunit
HTML
<script src="http://code.jquery.com/qunit/qunit-1.13.0.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.13.0.css">
<div id="qunit"></div>
<div id="qunit-fixture"></div>
JavaScript
function subfunc() {
throw "subfunc error";
}
function func() {
try {
subfunc();
} catch (e) {}
}
test("official cookbook example", function () {
throws(function () {
throw "error";
}, "Must throw error to pass.");
});
test("Would expect this to work", function () {
throws(subfunc(), "Must throw error to pass.");
});
test("Why do I need this encapsulation?", function () {
throws(function(){subfunc()}, "Must throw error to pass.");
});
test("Would expect this to fail, because func does not throw any exception.", function () {
throws(func(), "Must throw error to pass.");
});