Hi I have been trying to write test cases for my registration service. It has a url which it sends 4 values. the service is as follows:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'
interface registerResponse {
success: boolean,
message: string
}
@Injectable()
export class AuthService {
private _regurl ="http://localhost:3000/api/register"
constructor(private http: HttpClient) { }
registerUser(username,email,date, password) {
return this.http.post<registerResponse>(this._regurl, {
username,
email,
date,
password
})
}
}
I am still learning how to write test cases, i m trying to get the registerResponse to work.
here is what i have written till now
import { TestBed, async, inject } from '@angular/core/testing';
import {
HttpModule,
Http,
Response,
ResponseOptions,
XHRBackend
} from '@angular/http';
import { MockBackend } from '@angular/http/testing';
import { AuthService } from './auth.service';
import { HttpClient } from '@angular/common/http'
describe('RegisterService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpModule],
providers: [
{ provide: HttpClient, useValue: 'http://localhost:3000/api/register' },
AuthService,
{ provide: XHRBackend, useClass: MockBackend },
]
});
});
I know its not much I hv only defined mockbackend but any help would be appriciated
Thank You