2
我做了一些Javascript單元測試與QUnit庫,然後我想測試如果方法拋出RangeError。它以這種方式來完成:測試如果JS方法拋出RangeError與QUnit
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
我做的一切正常:我傳遞函數拋出錯誤,預期錯誤的實例和預期的消息。我有人會決定幫助我,我會很高興 - 提前謝謝你。
這就是它!很高興你找到了它。 – jakerella 2014-10-18 23:12:01