I am trying to implement functions for printing diamond in terms of test-based learning in javascript.
Diamond.prototype.outerSpace = function (current, widest) { var currentValue = this.getIndexOf(current); var widestValue = this.getIndexOf(widest); if (currentValue > widestValue) { throw new Error('Invalid combination of arguments'); } var spaces = widestValue - currentValue; return new Array(spaces + 1).join(' '); };
I have problems with error handling. The above function should throw an error if currentValue is greater than widestValue.
This is my snippet representing the test / spec:
it ("should throw an exception, if it is called with D and C", function () { var outerSpace = diamond.outerSpace.bind(diamond, 'D', 'C'); expect(outerSpace).toThrow('Invalid combination of arguments'); });
I also tried an anonymous function while waiting (..), but that also didn't work.
Console message: The expected function to reset is "Inval ...", but it throws an error: invalid combination of arguments.
I do not understand what to do with this information.
Edit: This is strange because it works with Jasmine v.1.3, but it did not work with jasmine v.2.3 ie or with karma, although the code is based on jasmine.
javascript tdd karma-runner jasmine karma-jasmine
Texas
source share