title: How to make my Jasmine Http post test more efficient?
body: <p>I am testing an angular 4 app using Jasmine/Karma. As of now I am testing my services. I have tested my first service successfully, that service just requests and returns a url. My next service is a post service. This service adds a model and a url to the page. I believe I have successfully mocked the service, but my code is not too efficient. I am trying to pass my data into 'body' so that I can pass bodyinto my expect statements. But I receive a few errors. Here is the spec:</p>
  
  <pre><code>      describe('httpService', () =&gt; {
          let service: HttpService;
          let httpClient: HttpTestingController;
  
          beforeEach(() =&gt; {
              TestBed.configureTestingModule({
                  imports: [HttpClientTestingModule],
                  providers: [HttpService]
              });
  
              service = TestBed.get(HttpService);
              httpClient = TestBed.get(HttpTestingController)
          });
  
          afterEach(() =&gt; {
            httpClient.verify();
          });
  
      it('should pass a model',  () =&gt; {
  
       const dummyPost: Test[] = [
      {userId: '1', id: 1, title: 'test', body: 'test'},
    ];
  
    service.add(dummyPost,'http://localhost:4200/dashboard').subscribe(body=&gt; {
      expect(dummyPost.length).toBe(1);
      expect(dummyPost).toEqual(dummyPost);
    });
  
  httpClient.expectOne({
    url: 'http://localhost:4200/dashboard'
  }).flush({
    dummyPost
  })
  </code></pre>
  
  <p>As you can see, I pass dummyPost to the expect syntax. I would rather pass body. I believe my syntax may be a little off. If I pass model, I get two errors :</p>
  
  <pre><code>Expected undefined to be 1.
  
  Expected Object({ dummyPost: [ Object({ userId: '1', id: 1, title: 'test', body: 'test' }) ] }) to equal [ Object({ userId: '1', id: 1, title: 'test', body: 'test' }) ]
  </code></pre>
  
  <p>This has be also believe that maybe my test is not working as I think it is. If I pass the model, dummyPost, everything passes. I can even add more instances of the model and test for more then 1, and it passes. If it helps, here is the service I am testing:</p>
  
  <pre><code>   add(model, url: string): Observable&lt;any[]&gt; {
      let headers = new HttpHeaders({
          'Content-Type':
          'application/json; charset=utf-8'
      });
      let options = { headers: headers };
      let body = JSON.stringify(model);
      return this.http.post(url, body, options)
          .map(this.extractData)
          .catch(this.handleErrorObservable);
   }
  </code></pre>
  
  <p>Thank you!</p>