angular - 在 Jasmine/Karma 测试中使用 mockError 时,apollo-angular 会抛出错误
问题描述
多年来,我已经测试过此类查询/突变的错误,但就在现在,我遇到了一个错误,我似乎无法弄清楚。
当我调用这个测试时,Apollo 为我所做的 errorMock 抛出了一个错误。有没有人遇到过这个错误?
这很有趣,因为使用相同逻辑的其他测试工作得很好,只是这个
it('should call errorHandler if getThirdPartyCompanies requests returns an error', fakeAsync(() => {
const spyOnHandleError = spyOn(component['errorHandlerService'], 'handleError');
component.getThirdPartyCompanies();
const op = controller.expectOne(thirdPartyCouriersGraphqlModel);
op.flush(
{
errors: [new GraphQLError('a')]
}
);
controller.verify();
tick(100);
flush();
expect(spyOnHandleError).toHaveBeenCalled();
}));
关于为什么会发生这种情况的任何提示?
提前致谢!
解决方案
所以....
public getThirdPartyCompanies(): void {
console.log('getThirdPartyCompanies');
this.courierService.getThirdPartyCourierList(this.cityId)
.pipe(takeUntil(this.subscriptionDestroyer))
.subscribe((req) => {
this.thirdPartyCourierList = req.data.thirdPartyCourierCompanies;
this.loadingThirdies = false;
}
), err =>{
this.errorHandlerService.handleError(err);
this.loadingThirdies = false;
};
}
这是我用于通话的代码。请注意,我在错误调用之前关闭了 observable。
我所要做的就是:
}, err =>{
this.errorHandlerService.handleError(err);
this.loadingThirdies = false;
};
});
以正确的方式关闭订阅,我得到了它的工作......
对于任何有同样问题的人,这就是答案!
推荐阅读
- javafx - 在另一个 JavaFX 窗口中关闭阶段时采取措施
- python - Raspberry GPIO:是否可以猜测连接到 gpio 引脚的设备类型?
- python - 获取具有多个变量的列的假人
- google-cloud-platform - 用于 Minecraft 服务器的 Google VM RAM
- typescript - TypeScript:通用扩展对象,只有可选键
- html - 调整轮播项目的大小
- mysql - 在 mysql 中使用 webscraper 为数据库插入编写触发器......不断收到不同的错误
- javascript - 是的嵌套模式验证
- c++ - 将值传递到数组/数组中的值丢失时出错
- networking - 是否可以知道哪个输入门触发了 Omnet++ 的 handleMessage() 方法?