我应该如何测试可观察对象抛出错误?
const target = () =>
Observable.of(1)
.map(() => Observable.throw('an error'));
我尝试了以下方法来检查Jasmine的错误:
expect(target().subscribe(x => x)).toThrow();
let failingFunction = () => target;
expect(() => failingFunction).toThrow();
target.subscribe(() => null, err => expect(err).toBeDefined());
答案 0 :(得分:-1)
你能做这样的事吗?
it('should throw an error', (done) => {
target()
.next(fail)
.catch((err) => {
expect(err).toBe('an error');
done();
});
});