I’m working on a very lightweight system to test a javascript framework I am building for work.
I’ve created a test function that acts as a wrapper invoking the function i am testing within a try/catch to report feedback without breaking my test cycle. The problem is that my catch isn’t getting called when I deliberately create an error.
My code….
/// <summary>
/// Acts as a wrapper to allow us to perform and report the result
/// of each individual
/// test without blocking further tests.
/// </summary>
/// <param name="selector" type="String">
/// The id jQuery selector e.g #versionTests to repot feedback to.
/// </param>
/// <param name="testFunction" type="Function">
/// The test function to call.
/// </param>
test: function (selector, testFunction) {
try {
// now we are calling our own callback function
if (typeof testFunction === 'function') {
testFunction.call();
}
} catch (e) {
jQuery(selector).addClass("error").append("<p>" + e.description + "</p>");
}
}
Thanks in advance….
EDIT.. Added called code for clarity.
The test function that I am calling is basically on that calls this….
testEqualizeHeight: function () {
PeachUI("div.heightTest").equalizeHeight();
}
Which calls this……. (this.selector is a property that reflect jQuerys selector.)
note the missing '$' on $selector.height(tallest);
equalizeHeight: function () {
/// <summary>
/// Equalizes the height of the specified element(s).
/// </summary>
var $tallest = 0, $selector = this.selector;
$selector.each(function () {
var $height = jQuery(this).height();
if ($height > $tallest) {
$tallest = $height;
}
});
// ie6 height is the same as min-height for other browsers.
if (PeachUI.browser.ie6) {
$selector.height(tallest);
} else {
$selector.css("min-height", $tallest);
}
}
When looking in your source code it appeared to me that you do this remarkable thing (last lines):
Here you pass a reference to
PeachTest.testNumerictoPeachTest.test, but you’re calling the other three test functions and pass the values those functions return toPeachTest.test.Remove the function call operators (
()) behind those parameters and your test function works as expected.