在this code sandbox中,执行以下测试:
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也会将其报告为通过。有想法吗?
答案 0 :(得分:1)
rxjs可观察对象是异步的。看一下this page,以帮助测试异步代码
您要添加以下完成的参数->
test("It should fail", done => {
source.subscribe(
x => {
expect(x).toContain("NOTHING")
done();
});
});