mercredi 22 mai 2019

error method http test with jasmine (angular 7)

I have a simple application in angular 7, which makes a list request of gifs, informing the amount of gifs and the search term, using giphy api.

I want to create a test that makes a request, and verify that the result of the list of gifs is greater than 0.

but I'm having many errors and I'm not understanding why

Service

private apiKey:string = "123";
private shortUrl:string = "//api.giphy.com/v1/gifs/search?q="

searchGif(term:string, limit:number):Observable<Gif[]> {
     let url:string = this.getUrl(term, limit);
     return  this.http.get<Gif[]>(`${url}/`);
}

Test

let service: GifSearchService;
let httpMock: any
let limit: number = 1;
let term: string = "dogs";

beforeEach(() => {
    httpMock = jasmine.createSpyObj('http', [ 'get', 'post' ]);
    service = new GifSearchService(httpMock);
});

it('Should return value when search for gifs', () => {
    let result = service.searchGif(term, limit);
    expect(result.length).toBeGreaterThan(0);
  });

Error

ERROR in node_modules/rxjs/internal/Observable.d.ts(14,60): error TS1183: An implementation cannot be declared in ambient contexts. src/app/gif-list/gif-list.component.spec.ts(33,19): error TS2339: Property 'length' does not exist on type 'Observable'.

Aucun commentaire:

Enregistrer un commentaire