I am trying to write a unit test for the function below
public getDataWithAddress(myRequest: Address): Observable<any> {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Cache-Control': 'no-cache, no-store, must-revalidate, post-check=0, pre-check=0',
'Pragma': 'no-cache',
'Expires': '0'
})
};
Address Interface:
export interface Address {
AddressLine1?: string;
City?: string;
StateProvince?: string;
PostalCode?: string;
ReturnValues?: string;
}
My unit test
describe('HttpService', () => {
const address= {
AddressLine1: '3514 W PIERCE ST',
City: 'PHOENIX',
StateProvince: 'AZ',
PostalCode: '85009'
};
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
HttpClientTestingModule,
RouterTestingModule
],
providers: [
HttpService,
DataMappingService,
GoogleAnalyticsEventsService
]
});
service =TestBed.get(HttpService);
});
//Address
it('expect to retrun addressdata'),
inject(
[
HttpTestingController,HttpService
],
(httpMock: HttpTestingController, service: HttpService) =>{
//We call service for address
service.getDataWithAddress(address).subscribe(data => {
expect (data).toEqual(address);
});
// We set the expectations for the HttpClient mock
const req =httpMock.expectOne('http://localhost:4201/api/mydata/address');
expect(req.request.method).toEqual('POST');
// Then we set the fake data to be returned by the mock
req.flush({address});
httpMock.verify();
});
});
when the test runs i get :pending specs
What am i missing here ?