lundi 4 juin 2018

Test a function that calls a http service inside component Angular5

I need to test this function.

When I click this function getallproductcomponent(), execute this service function getallproductservice() and return all products. Any idea please, how to test both in component?

  getallproductcomponent() {
    this.ws.getallproductservice().subscribe(
      item=> {
        this.item= item;
      }
    );
  }

I can testing only getallproductservice. Below you can see my scripts that's work good. How to testing getallproductcomponent() {}

it('testing',
    async(inject([ProductService], (service: ProductService) => {
        TestBed.get(MockBackend).connections.subscribe(
            (connection: MockConnection) => connection.mockRespond(new Response(
                new ResponseOptions({
                                    })
            ))
        );
        service.getallproductservice().subscribe(items => {
            expect(items[0].alarmdesc).toEqual('call');
        });
    })))

Any idea please?

Aucun commentaire:

Enregistrer un commentaire