笑话报告测试通过,即使期望断言失败 [英] Jest reports that test passes even though expect assertion fails
本文介绍了笑话报告测试通过,即使期望断言失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在此代码沙箱中,执行以下测试:
import { of } from "rxjs";
import { map } from "rxjs/operators";
const source = of("World");
test("It should fail", () => {
source.subscribe(x => expect(x).toContain("NOTHING"));
});
即使期望失败,Jest也会将其报告为通过.有想法吗?
Jest reports it as passing, even though the expectation fails. Thoughts?
推荐答案
rxjs可观察对象是异步的.看一下此页面以帮助测试异步代码
rxjs observables are asynchronous. Take a look at this page to help with testing asynchronous code
您要添加以下完成的参数->
You want to add the done argument as below ->
test("It should fail", done => {
source.subscribe(
x => {
expect(x).toContain("NOTHING")
done();
});
});
这篇关于笑话报告测试通过,即使期望断言失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文