我正在尝试编写一个测试,以确保我正在执行的无效实例化会产生异常。测试如下:
describe('Dialog Spec', function () {
"use strict";
it("should throw an exception if called without a container element", function () {
expect(function() {
new Dialog({});
}).toThrow(new Exception("InvalidArgumentException", "Expected container element missing"));
});
});
Dialog() 类:
function Dialog(args) {
if (undefined === args.containerElement)
throw new Exception("InvalidArgumentException", "Expected container element missing");
this.containerElement = args.containerElement;
}
}
我在茉莉花中遇到了以下失败。
Expected function to throw Exception InvalidArgumentException: Expected container element missing , but it threw Exception InvalidArgumentException: Expected container element missing
我的例外类:
function Exception(exceptionName, exceptionMessage) {
var name = exceptionName;
var message = exceptionMessage;
this.toString = function () {
return "Exception " + name + ": "+ message;
};
}
我究竟做错了什么?