Reputation: 656
I'm trying to get started with unit testing with javascript. I'm using jasmine framework 2.5.2 and Netbeans 8.2 as my IDE.
This is the simple code i want to test:
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;
}
}
This is my test:
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"]));
});
});
So when i run the test, the first two methods pass, but i get an error for the last method "concenate":
TypeError: ListHandler.concatenate(...).toEqual is not a function
However, when i just execute it like alert(ListHandler.concatenate([1,2,5], ["a", "b", "c"]));
it works fine. Can someone explain to me why jasmine complains?
Upvotes: 0
Views: 35
Reputation: 3437
You have a misplaced closing paranthesis.
Try;
expect(ListHandler.concatenate([1,2],["a","b"])).toEqual([1,2,"a","b"]);
Upvotes: 1