Angular 2 mock response not working
<p>I have the following Angular 2 test:</p>

<pre><code>/* tslint:disable:no-unused-variable */

import { provide  } from '@angular/core';
import { MockBackend  } from '@angular/http/testing';

import {
  Http,
  HTTP_PROVIDERS,
  Response,
  ResponseOptions,
  BaseRequestOptions,
  ConnectionBackend,
  XHRBackend

} from '@angular/http';

import {
  beforeEach, beforeEachProviders,
  describe, xdescribe,
  expect, it, xit,
  async, inject

} from '@angular/core/testing';

import { BookService  } from './book.service';

describe('Book Service', () =&gt; {
  beforeEachProviders(() =&gt; [
    BookService,
    HTTP_PROVIDERS,
    MockBackend,
    BaseRequestOptions,
    { provide: XHRBackend, useExiting: MockBackend  },
    provide(Http, {
        useFactory: function (backend:ConnectionBackend, defaultOptions:BaseRequestOptions) {
        return new Http(backend, defaultOptions);
      },
      deps: [MockBackend, BaseRequestOptions]
    })
  ]);

  it('should assign a list of books', inject([BookService, MockBackend, Http], (service, backend, http) =&gt; {
     var response;

     backend.connections.subscribe(c =&gt; {
       expect(c.request.url).toEqual('/api/books.json');
       c.mockRespond(new Response(new ResponseOptions({body: {message: 'thank you'}})));

       });

     http.get('/api/books.json').subscribe(data =&gt; response = data);

     expect(response).toEqual({ message: 'thank you'  });

  }));

});
</code></pre>

<p>The part I want to focus on is this:</p>

<pre><code>  it('should assign a list of books', inject([BookService, MockBackend, Http], (service, backend, http) =&gt; {
     var response;

     backend.connections.subscribe(c =&gt; {
       expect(c.request.url).toEqual('/api/books.json');
       c.mockRespond(new Response(new ResponseOptions({body: {message: 'thank you'}})));

       });

     http.get('/api/books.json').subscribe(data =&gt; response = data);

     expect(response).toEqual({ message: 'thank you'  });

  }));
</code></pre>

<p>When I run the test, I get:</p>

<p><code>Expected Response with status: null null for URL: null to equal Object({ message: 'thank you'  }).</code></p>

<p>Thinking it's maybe an async issue, I changed my expectation to this:</p>

<pre><code>http.get('/api/books.json').subscribe(data =&gt; {
   expect(data).toEqual({ message: 'thank you'  });
});
</code></pre>

<p>But I'm still getting the same failure message.</p>

<p>What can I do to get the mock response to take effect?</p>