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

后端 未结 11 1761
春和景丽
春和景丽 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条回答
  •  猫巷女王i
    2020-12-12 12:51

    I also had this error, which truth be told is fairly non talkative.

    It was related to the HTTP calls trough my services

    I use myService.ts with 2 methods

    get();
    getAll();
    

    I am mocking this service : mockMyService.ts

    The error was here because my component was using getAll() method that I forgot to implement in the mockMyService, so I just added the method :

    private mockObjects = [
    {
      'id': '1',
      'champ1': 'TECH',
      'champ2': 2,
      'champ3': 'Data bidon'
    },
    {
      'id': '2',
      'champ1': 'TECH',
      'champ2': 2,
      'champ3': 'Data au pif'
    },
    {
      'id': '3',
      'champ1': 'FUNC',
      'champ2': 3,
      'champ3': 'Data quelconque'
    },
     ];
    
    getAll(): Observable {
      return Observable.of(this.mockObjects);
    }
    

    Error was gone :)

提交回复
热议问题