title: How to unit test a function that returns a promise in angular
body: <p>I have a function inside a component that will call a service method with 3 arguments and that will return a promise. I want to unit test the function using karma jasmine in angular. Did I make any mistakes here?</p>
  <p>component code</p>
  <pre><code>getHeaderData() {
   return this.service.getList({
      id: this.id,
      name: this.name,
      pageName: constants.PAGE_NAME
    });
  }
  </code></pre>
  <p>service code</p>
  <pre><code>getList(param): Promise&lt;any&gt; {
   const params = new HttpParams()
      .set('cId',param.id)
      .set('cName',param.name)
      .set('cPageName',param.pageName);
    return new Promise((resolve, reject) =&gt; {
     try {
         this.httpService.get('getHeader', {params}).subscribe(data =&gt; {
           resolve(data);
          });
     }catch (err){
       reject(err);      
      }
   });
  }
  </code></pre>
  <p>spec file code</p>
  <pre><code>it('test getHeaderData()', async () =&gt; {
    const serviceSpy: Service = TestBed.get(Service);
    SpyOn(serviceSpy, 'getList').and.ReturnValue(Promise.resolve(constants.response));
    expect(serviceSpy.getList).toHaveBeenCalled();
    expect(component.getHeaderData()).toBe(constants.response);
  });
  </code></pre>
  <p>the actual return value form the service is an array of objects the same I have created in the constant file as response and with the above code I'm getting below error. I'm not sure this is the right way to do it.</p>
  <blockquote>
  <p>Argument of type  is missing the following properties form the ' { then: ExpectedRecursive&lt;{&lt; TResult1 etc......</p>
  </blockquote>