We recently upgraded to Angular 6.0.3, RxJs 6.2.0 and jest 23.1.0 (upgrading from RxJS 5 & Angular 4).
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();
});
});
The expect-Statement gets executed, but the test still passes. We didn't observe this behaviour with the previous RxJs version and Jest.
Try to use done.
it("should fail", (done) => {
const obs = Observable.create((observer) => {
observer.next(false);
});
obs.subscribe((value) => {
console.log(value); // => false
expect(value).toBeTruthy();
done();
});
});
more info
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With