Jest 报告测试通过,即使 expect 断言失败
Jest reports that test passes even though expect assertion fails
在 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 报告它通过,即使预期失败。想法?
rxjs observables 是异步的。查看 this page 以帮助测试异步代码
您想添加完成参数如下 ->
test("It should fail", done => {
source.subscribe(
x => {
expect(x).toContain("NOTHING")
done();
});
});
在 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 报告它通过,即使预期失败。想法?
rxjs observables 是异步的。查看 this page 以帮助测试异步代码
您想添加完成参数如下 ->
test("It should fail", done => {
source.subscribe(
x => {
expect(x).toContain("NOTHING")
done();
});
});