2014-10-18 8 views
2

QUnit 라이브러리에서 몇 가지 Javascript 단위 테스트를 수행 한 다음 메서드가 RangeError를 throw하는지 테스트하려고합니다. 애니메이션 클래스는 기능에 의해 해결하기 때문에 ("... ,, 슬라이드),JS 메서드가 QUnit에서 RangeError를 throw하는지 테스트

QUnit.test("Resolve slide animation from left", function(assert) { 
var myOwnCreator = new MyOwnCreator(); 
assert.equal(myOwnCreator.resolveAnimationType("slideSide", "show", "left"), 
    "slide-left-in"); 
assert.equal(myOwnCreator.resolveAnimationType("slideSide", "hide", "left"), 
    "slide-left-out"); 
assert.throws(myOwnCreator.resolveAnimationType("slideSide", "hide"), 
    new RangeError(), 
    " If animation type is 'slideSide', you have to provide correct direction" 
    + "to identify animation properly, direction cannot be 'undefined'"); 
}); 

먼저하고 통과 번째 테스트 확인되었다 그러나 세 번째 시험은 사망 : 그것은이 방법으로 수행 할 수있다.

Died on test #3  at file... 

RangeError를 던지기 때문에 RangeError가 발생하지만 OK입니다. 단위 테스트에서 어떻게 잡을 수 있는지 이해할 수 없습니다. QUnit 설명서를 이해하는 경우 : QUnit throws documentation

나는 모든 작업을 수행합니다. 오류를 throw하는 함수, 예상되는 오류 및 예상되는 메시지의 인스턴스를 전달합니다. 나는 아무도 나를 돕기로 결심했다, 나는 매우 행복 할 것이다 - 미리 감사드립니다.

답변

4

나는 혼자서 대답을 찾았습니다. 대신 호출 기능 :

assert.throws(myOwnCreator.resolveAnimationType("slideSide", "hide"), 
    new RangeError().... 

내가 (assert.throws에 전달한다) 내 함수를 호출 기능이 같은 : 그것 뿐이다

assert.throws(function(){ 
    myOwnCreator.resolveAnimationType("slideSide", "hide"); 
    }, 
    new RangeError(--message which function should throw in error--)... 
+1

! 다행 이군. – jakerella