我正在使用
"karma": "^3.0.
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^2.0.4",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^1.3.1",
我有一个要测试的utils.service.ts。 该服务有下一种方法
public static isEmptyObject(obj: Object): boolean {
if (!(obj instanceof Object) || Array.isArray(obj)) {
throw new Error('Object was expected');
}
return Object.keys(obj).length === 0;
}
我想要的是检查没有给出对象时是否引发错误。我正尝试以另一种方式
it('#isEmptyObject should throw error when not an object given', () => {
expect(US.isEmptyObject('sadasd')).toThrowError(/(Object was expected)/);
});