I tried this test for testing my service:
Result for this is successful, but I think that this must be unsuccessful, because I have only 5 products.
it('testing getall products', () => {
const proservice = TestBed.get(ProductService);
proservice.productsgetall().subscribe(products => {
expect(product.length).toEqual('10') // This is unsuccessful, because I have only 5 products.
});
})
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?
Aucun commentaire:
Enregistrer un commentaire