0
我想用javascript開始單元測試。我使用茉莉花框架2.5.2和Netbeans 8.2作爲我的IDE。單元測試Javascript - 茉莉花測試失敗,雖然代碼正常工作
這是簡單的代碼,我想測試:
var ListHandler = {
"reverseList": function (inputList) {
var list = inputList,
reversedList = [],
length = list.length;
for (var i = 0; i < length; i++) {
reversedList.push(list[length - i - 1]);
}
return reversedList;
},
"sumUp": function (inputList) {
var count = 0;
for (var i = 0; i < inputList.length; i++) {
count += inputList[i];
}
return count;
},
"concatenate": function (inputList1, inputList2) {
var result = inputList1.concat(inputList2);
return result;
}
}
這是我的測試:
describe("List Handler", function(){
it("should return reversed List",function(){
expect(ListHandler.reverseList([1,2,3])).toEqual([3,2,1]);
});
it("should return sum of list values",function(){
expect(ListHandler.sumUp([1,2,3])).toEqual(6);
});
it("should return concatenated List", function(){
expect(ListHandler.concatenate([1,2],["a","b"]).toEqual([1,2,"a","b"]));
});
});
所以當我運行測試,前兩種方式傳遞,但我得到的錯誤的最後一個方法「concenate」:
TypeError: ListHandler.concatenate(...).toEqual is not a function
然而,當我只需要執行它像alert(ListHandler.concatenate([1,2,5], ["a", "b", "c"]));
它活像很好。有人能向我解釋爲什麼茉莉花會抱怨嗎?