title: UnitTest Mock Http response in Angular2 (2.1.0) Service
body: <p>I am very confused by the different sources online about testing Angular2, mainly due to differences in versions. I am using Angular 2.1.0 final and I don't understand how to mock a simple http response for my service test class below:</p>
  
  <pre><code>import { TestBed, async, inject } from '@angular/core/testing';
  import { PersonService } from '../services/person.service';
  import { Person} from '../models/Person';
  import { MOCK_DATA_PERSON } from '../test/mocks/mock-data-person';
  
  // HTTP mocking imports
  import { Http, BaseRequestOptions, Response, HttpModule, ResponseOptions } from '@angular/http';
  import { MockBackend, MockConnection } from '@angular/http/testing';
  
  
  describe('PersonService', () =&gt; {
      beforeEach(async(() =&gt; {
          TestBed.configureTestingModule({
              providers: [
                  PersonService,
                  MockBackend,
                  BaseRequestOptions,
                  {
                      provide: Http,
                      useFactory: (backend: MockBackend, options: BaseRequestOptions) =&gt; {
                          return new Http(backend, options);
                      },
                      deps: [MockBackend, BaseRequestOptions],
                  }
              ],
              imports: [
                  HttpModule
              ]
          });
  
          TestBed.compileComponents();
      }));
  
      it('returns a list of persons', async(inject([MockBackend, PersonService], (backend: MockBackend, service) =&gt; {
  
          backend.connections.subscribe(
              (connection: MockConnection) =&gt; {
                  connection.mockRespond(new Response(
                      new ResponseOptions({
                          body: JSON.stringify({name: "Bob", surname : "Jones"})
                      })));
              });
  
          service.getPersons()
              .subscribe(persons=&gt; {
                  expect(persons.length).toBeDefined();
                  expect(persons.length).toBe(1);
              }).catch(error =&gt; console.log(error));
      })));
  
  
  });
  </code></pre>
  
  <p>given the getPersons method looks like:</p>
  
  <pre><code>getPersons (): Observable&lt;Person[]&gt; {
      return this.http.get(this.getAllUrl)
        .map(res.json().data)
        .catch(this.handleError);
    }
  </code></pre>
  
  <p>i am getting the error <code>"Failed: this.http.get(...).map is not a function"</code></p>