我试图实现在JavaScript中学习测试驱动开发方面打印钻石的功能。茉莉花抛出错误期望().Throw而不是识别抛出的错误
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(' ');
};
我在错误处理中遇到问题。如果currentValue大于widestValue,上面的函数应该会抛出一个错误。
这是代表在测试/规格我的片断:
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');
});
我也试图与一个匿名函数在期待(..),但是这也没有工作。
控制台消息是:预期的函数抛出'Inval ...'但它抛出错误:无效的参数组合。
我不明白,我该怎么处理这些信息。
编辑:这很奇怪,因为它与Jasmine v.1.3一起工作,但它并不适用于茉莉花v.2.3,即与业力,尽管基于茉莉花的代码。