title: Implement unit testing with jasmine/karma by mocking Http Post - Angular 5
body: <p>I am completely new to unit testing and I am implementing unit testing using jasmine/karma for the first time. I am facing few issues in understanding how I should implement testing by mocking for Http Post. I have gone through few solutions such as : 
  <a href="https://stackoverflow.com/questions/46420640/angular-4-unit-testing-with-jasmine-karma-with-http-post-mocking-how-to-fix">solution1</a> and <a href="https://stackoverflow.com/questions/44076086/how-do-i-mock-out-http-post-in-angular-without-using-testbed">solution2</a></p>
  
  <p>But still I have faced few issues in understanding them and have also faced few errors. </p>
  
  <p>By following solution2 I have tried to implement as follows:</p>
  
  <p><strong>http.service.ts</strong></p>
  
  <pre><code> update(id,password,url){
  
      let content = {
          "username": id,
          "password":password,
  
       }
  
       const httpOptions = {
        headers: new HttpHeaders({
          'Content-Type':  'application/json'
        })
      };
  
       return this.http.post(url,content,httpOptions).subscribe((data:any) =&gt; {
  
          if(data.length){
            return true;
          }
          else{
            return false;
          }
        })
  </code></pre>
  
  <p><strong>http.service.spec.ts</strong></p>
  
  <pre><code>import { TestBed, inject } from '@angular/core/testing';
  import { HttpClientModule } from '@angular/common/http'; 
  import { HttpService } from './http.service';
  import {HttpModule, XHRBackend,Response,ResponseOptions, Connection} from 
  '@angular/http';
  import {  of } from 'rxjs';
  import { MockBackend } from '@angular/http/testing';
  
   describe('HttpService', () =&gt; {
   let mockbackend, service;
   beforeEach(() =&gt; {TestBed.configureTestingModule({
   imports:[HttpClientModule, HttpModule],
   providers:[{
   provide: XHRBackend, useclass: MockBackend
   }]
  
   })
   });
  
    beforeEach(inject([ XHRBackend], (_service, 
    _mockbackend) =&gt; {
    service = _service;
    mockbackend = _mockbackend;
    }));
  
    it('post method is successfull',() =&gt;{
    const status = 'success';
    const username = '5555555';
    const password = 'test';
    const currentUserExpected = JSON.stringify({status:status});
    const response = { status : status};
    const responseOptions = new ResponseOptions();
    responseOptions.body = JSON.stringify(response);
    mockbackend.connections.subscribe(connection =&gt;{
    connection.mockRespond(new Response(responseOptions));
    });
    service.update(username,password).subscribe(respond =&gt;{
    expect(respond).toEqual(true)
    })
     })
  </code></pre>
  
  <p>The error I am receiving is this:</p>
  
  <p><strong>Error</strong></p>
  
  <blockquote>
    <p>Cannot read property 'connections' of undefined</p>
  </blockquote>
  
  <p>Can someone please help me out in understanding where I am going wrong. </p>
  
  <p>Also I would like to receive reference to any documentation which can help me better understand this. </p>