4

此代码沙箱中,执行以下测试:

    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 将其报告为通过,即使期望失败。想法?

4

1 回答 1

2

rxjs observables 是异步的。查看此页面以帮助测试异步代码

您想添加 done 参数,如下所示 ->

test("It should fail", done => {
  source.subscribe(
    x => {
      expect(x).toContain("NOTHING")
      done();
    });
});
于 2018-11-07T21:46:26.850 回答