I have class that hold's property array and some functionality in it. The class has remove method that removes number of the specific index:
class SortedList {
constructor() {
this.list = [];
}
add(element) {
this.list.push(element);
this.sort();
}
remove(index) {
this.vrfyRange(index);
this.list.splice(index, 1);
}
I make Mocha tests for this class and i want to throw error when parameter of remove functionality are negative number or greater than the array size. Problem is that I can't get an error message. I try the following:
it('check for incorrect input', function () {
sorted.add(2);
sorted.add(3);
expect(sorted.remove(-1)).to.throw(Error('Index was outside the bounds of the collection.'))
});