Angular tests failing with Failed to execute 'send' on 'XMLHttpRequest'

后端 未结 11 1751
春和景丽
春和景丽 2020-12-12 12:11

I am trying to test my angular 4.1.0 component -

export class CellComponent implements OnInit {
  lines: Observable>;
  @Input() dep         


        
11条回答
  •  失恋的感觉
    2020-12-12 13:05

    What I would be doing is:

    Add console.log() s, line after line in ngOnint() and find out how far it goes , then inspect the line which it wont pass through.

    Ex:

    ngOnInit() {
        this.route.paramMap
            .switchMap(params => {
                this.busy = true;
                this.updateErrors(null);
    
                console.log(params);
    
                **const id = params.get('id');**
                console.log(id);
    
                if (id === 'new') {
                    this.editMode = true;
                    return Observable.of(GroupComponent.newGroup());
                }
                return this.apiService.getGroup(id);
            })
        }
    

    This was failing on my test with the same error in this post. As shown above, I had two console.logs. First one passed thorugh , but the second one not. So I realized the issue is on line const id = params.get('id'); and I fixed it.

    Hope this will help someone.

提交回复
热议问题