【发布时间】:2016-06-16 17:46:15
【问题描述】:
如何测试Jasmine 中是否捕获到异常?
如果我删除 try...catch 语句,预期是正确的,但我对此不感兴趣。
规格
import { foo } from './src';
describe('app', () => {
it('should match if an exception was catched', () => {
expect(() => foo()).toThrow();
});
});
来源
function foo() {
try {
throw new Error();
} catch(e) {
console.log(e);
}
}
export { foo };
【问题讨论】:
标签: javascript node.js unit-testing jasmine