I am a beginner in unit testing in Angular using jasmine. How do I test a service using jasmine? Below is a service:
import { Injectable } from "@angular/core";
import { environment } from "src/environments/environment";
import { MessageService } from "../message/message.service";
import { Observable } from "rxjs";
import { catchError } from "rxjs/operators";
import { ShareDto } from "src/app/model/share/share-dto";
import { HttpHandlerService } from "../http-handler/http-handler.service";
@Injectable({
providedIn: "root"
})
export class xxxService {
private apiUrl = environment.requestUrl;
private shareDefaultUrl = "/share";
constructor(
private http: HttpHandlerService,
private messageService: MessageService
) {}
sharing(body: ShareDto): Observable<any> {
const url = `${this.shareDefaultUrl}`;
return this.http
.post(this.apiUrl + url, body)
.pipe(catchError(this.messageService.handleError));
}
}
How do I write the testcase in spec file to test the methods present in this service? Please help.