나는 매우 가벼운 시스템에서 일하고있는 자바 스크립트 프레임 워크를 테스트하고있다.자바 스크립트 이벤트 처리
필자는 테스트주기를 위반하지 않고 피드백을보고하기 위해 try/catch 내에서 테스트하는 함수를 호출하는 래퍼 역할을하는 테스트 함수를 만들었습니다. 문제는 고의적으로 오류를 만들 때 내 캐치가 호출되지 않는 것입니다. 사전에
내 코드 ....
/// <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>");
}
}
감사합니다 ....
편집 ... 추가는 명확성을 위해 코드를했다.
내가 부르고 테스트 기능이 호출
testEqualizeHeight: function() {
PeachUI("div.heightTest").equalizeHeight();
}
....... (this.selector
이 jQuerys 선택을 반영하는 속성입니다.) ... 기본적으로 즉,이 호출에 $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);
}
}
오류를 생성하는 코드를 게시 할 수 있습니까? – cambraca