title: Angular 2/4 Jasmine unit testing a service with json object structure
body: <p>I have a service that I want to unit test.   It has a current json array object in which when this observable is subscribed to, it works fine.</p>
  
  <p>However,  what am I doing wrong with my unit test?</p>
  
  <p><strong>Service code</strong> </p>
  
  <pre><code>getTrackerData(): (Observable&lt;any&gt;) {
      return Observable.of(tracker)
          .do(data =&gt; console.log('trackerdata', data))
          .catch(this.handleError)
  }
  
  private handleError(error: Response) {
      console.error(error);
      return Observable.throw(error.json().error || 'Server error');
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>DATA</strong> </p>
  
  <pre><code>const tracker =
  [{
      "tracker": "2278474849", "task": 1, "agent": 1, "session": "2278474849-1-1"
   }
  ]
  </code></pre>
  
  <p><strong>Unit Test</strong></p>
  
  <pre><code>/// &lt;reference path="../../../../node_modules/@types/jasmine/index.d.ts" /&gt;
  import { TestBed, fakeAsync, inject, tick, async, ComponentFixture, ComponentFixtureAutoDetect } from '@angular/core/testing';
  import { MockBackend } from '@angular/http/testing'
  import { Http, BaseRequestOptions, Response, ResponseOptions } from '@angular/http'
  import { BrowserModule, By } from "@angular/platform-browser";
  import { ReactiveFormsModule } from '@angular/forms';
  import { Observable } from 'rxjs/Rx'
  import { TrackerService } from './tracker.service'
  
  
  describe('tracker service', () =&gt; {
  
      let mockResponse, matchingItem, connection
  
      beforeEach(async(() =&gt; {
          TestBed.configureTestingModule({
              providers: [
                  TrackerService,
                  MockBackend,
                  BaseRequestOptions,
                  {
                      provide: Http,
                      useFactory: (backend, defaultOptions) =&gt; new Http(backend, defaultOptions),
                      deps: [MockBackend, BaseRequestOptions]
                  },
              ]
          });
          const items =
              [{
                  "tracker": "2278474849", "task": 1, "agent": 1, "session": "2278474849-1-1"
              }
              ];
          mockResponse = new Response(new ResponseOptions({ body: items, status: 200 }));
      }));
  
  
      describe('getTrackerData', () =&gt; {
          //subscribe to connection and storing it later
          it('should return all items', inject([TrackerService, MockBackend], (service: TrackerService, backend: MockBackend) =&gt; {
              backend.connections.subscribe(connection =&gt; {
                  connection.mockRespond(mockResponse);
              });
              service.getTrackerData() //{ "tracker": "2278474849", "task": 1, "agent": 1, "session": "2278474849-1-1"  }
                  .subscribe((items: any =&gt; {
                     expect(this).toBe(2);
              }));
  
      })
  
  });
  </code></pre>
  
  <p>I seem to be getting errors in the <code>describe</code> section   ,  Problem is that I'm not used to writing javascript/angular unit test, along with mixing up a few examples in the project I'm on coupled with online examples.  </p>
  
  <p>Seems like what I want/need to do should be way simple , but yet I imported so many dependencies that this is now just confusing.</p>
  
  <p>Anyone know what I need to do?</p>