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

后端 未结 11 1750
春和景丽
春和景丽 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 12:53

    For my case there was a mock data problem and in case of Array, I was returning string from the mock.

    someApi = fixture.debugElement.injector.get(SomeApi);
    spyOn(someApi, 'someMethod')
      .and.returnValue(Observable.of('this is not a string but array'));
    

    The error message is really distracting and was not telling the actual error. Running ng test --source=false pointed the correct error and line, and helped me to fix it quickly.

    Many time it happens when you mock data is incomplete or incorrect.

提交回复
热议问题