Angular REST API调用的测试顺序-“;没有当前的规范”;
我正在尝试测试as REST服务的创建/删除顺序。下面的示例始终在IDE中传递,但在Karma/Jasmine调试器中给出了一个错误Angular REST API调用的测试顺序-“;没有当前的规范”;,angular,rest,testing,observable,Angular,Rest,Testing,Observable,我正在尝试测试as REST服务的创建/删除顺序。下面的示例始终在IDE中传递,但在Karma/Jasmine调试器中给出了一个错误 "expect' was used when there was no current spec, this could be because an asynchronous test timed out" 每个测试单独运行正常 it(“创建后应返回已删除项目的数量”,完成=>{ const ex1=sgformsService.getOrCreate(“E
"expect' was used when there was no current spec,
this could be because an asynchronous test timed out"
每个测试单独运行正常
it(“创建后应返回已删除项目的数量”,完成=>{
const ex1=sgformsService.getOrCreate(“Endoskopie”,9999,“2019-03-20”);
const ex2=sgformsService.deleteByParameter(
“Endoskopie”,
9999,
"2019-03-20"
);
const ex=ex2.pipe(concat(ex1)).subscribe((val:number)=>{
期望值(val)、toEqual(7);
完成();
});
});
我没有完全理解值是如何返回的,我希望只返回最后一个值。以下是工作解决方案:
it('should return the number of deleted items after creation', done => {
const ex1 = sgformsService.getOrCreate('Endoskopie', 9999, '2019-03-20')
const ex2 = sgformsService.deleteByParameter('Endoskopie', 9999, '2019-03-20')
const ex= ex1.pipe(concat(ex2))
.subscribe((val: number|SgformsBase[]) => {
if (typeof(val) === "number") {
expect(val).toEqual(7)
done()
}
});
})
您能否创建一个最小的工作示例?所以有可能对测试进行一些调整,从而解决问题?错误消息可能表明,在调用subscribe中的实际expect之前,测试已经结束。另一个问题可能是concat首先发出第一个可观测值,然后从concated可观测值发出。这意味着,expect(val)位在当前设置中被触发两次。不太确定这是否是有意的。为了进一步提供帮助,有必要了解getOrCreate和deleteByParam返回的是什么。是否有延迟或类似的事情?谢谢你的调查,@Erbsenkoenig。见下文。我需要更多的调试来理解这些值是如何返回的。但是,如果您只对DeleteByParameter发出的值感兴趣,那么可以使用flatMap操作符,这样您就不需要检查类型,也不需要运行该方法两次。