Angular Testing抛出可观察的回调

时间:2019-06-16 08:14:10

标签: angular jasmine

我正在使用Angular 8和Jasmine 3.4,并且在测试以下代码方面遇到一些困难

      ngOnInit(){
        this.myService.myMethod().subscribe(
        responseOk => {
            // some code
        },
        responseKo => {
            if (responseKo instanceof HttpErrorResponse) {
                if (responseKo.status === 404) {
                    // some code
                } else if (responseKo.status === 403) {
                    // some code
                } else {
                    throw responseKo;
                }
            } else {
                throw responseKo;
            }
        });
      }

如何对代码为“ throw responseKo”的分支进行单元测试?

0 个答案:

没有答案