I'm fairly new to unit testing and can't seem to unit test a simple service, even using the docs...
Here's my service, I want to test my getBooks Method
import { Injectable } from '@angular/core';
import { Observable, map, of } from 'rxjs';
import { HttpClient } from '@angular/common/http';
export interface Book {
id: string,
volumeInfo: {
title: string,
authors: Array<string>,
};
}
@Injectable({
providedIn: 'root'
})
export class BooksService {
constructor(private http: HttpClient) { }
getBooks(): Observable<Array<Book>> {
return this.http.get<{ items: Book[] }>(
'https://www.googleapis.com/books/v1/volumes?maxResults=5&orderBy=relevance&q=oliver%20sacks'
) .pipe(map((books) => books.items || []));
}
}