在subscribe()中失败的expect()不会将测试标记为无效 [英] Failing expect() inside subscribe() does not mark test as invalid
本文介绍了在subscribe()中失败的expect()不会将测试标记为无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们最近升级到Angular 6.0.3,RxJs 6.2.0和jest 23.1.0(从RxJS 5和Angular 4升级).
We recently upgraded to Angular 6.0.3, RxJs 6.2.0 and jest 23.1.0 (upgrading from RxJS 5 & Angular 4).
Jest&似乎有问题RxJs作为subscribe-Block中失败的期望陈述,不会将测试标记为失败.这是一个最小的示例:
There seems to be a problem with Jest & RxJs as failing expect-statements inside a subscribe-Block do not mark the test as failed. Here's a minimal example:
it("should fail", () => {
const obs = Observable.create((observer) => {
observer.next(false);
});
obs.subscribe((value) => {
console.log(value); // => false
expect(value).toBeTruthy();
});
});
expect-Statement被执行,但是测试仍然通过.在以前的RxJs版本和Jest中,我们没有观察到这种行为.
The expect-Statement gets executed, but the test still passes. We didn't observe this behaviour with the previous RxJs version and Jest.
推荐答案
尝试使用完成.
it("should fail", (done) => {
const obs = Observable.create((observer) => {
observer.next(false);
});
obs.subscribe((value) => {
console.log(value); // => false
expect(value).toBeTruthy();
done();
});
});
这篇关于在subscribe()中失败的expect()不会将测试标记为无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文