jeudi 31 mai 2018

Testing Service. TypeError: done.fail is not a function

I tried this test for testing my service:

Show this error:

TypeError: done.fail is not a function

test file

 it('should return reasonable json ssss', inject([ProductService, MockBackend], async((service: ProductService, mockBackend: MockBackend) => {
       const mockResponse = {
            data: [
                { id: 0, details: 'All cats are lions' },
                { id: 1, details: 'Video 1' },
                { id: 2, details: 'Video 2' },
                { id: 3, details: 'Video 3' },
            ]
        };
        mockBackend.connections.subscribe(connection => {
            connection.mockRespond(new Response(
                new ResponseOptions({
                    body: [
                        { id: 0, details: 'All cats are lions' },
                        { id: 1, details: 'Video 1' },
                        { id: 2, details: 'Video 2' },
                        { id: 3, details: 'Video 3' },
                    ]
                })));
        });
        service.productsgetall().subscribe((facts) => {
            console.log(facts)
            expect(facts[0].details).toEqual('ffff');
        });
    })));

- My service.ts

public productsgetall(): Observable<Products[]> {
                ...
 return this.http.get(Api.getUrl(Api.URLS.productsgetall), {
      headers: headers
    }).map((response: Response) => {
        let res = response.json();
        if (res.StatusCode === 1) {
          this.auth.logout();
        } else {
          return res.StatusDescription.map(aa => {
            return new Products(aa);
          });
        }
  });
}

Can you ask me, what is the problem in my code, how to write good testing? If this testing is'n good, please suggest something. Thnx

Aucun commentaire:

Enregistrer un commentaire