title: Testing async http service - scope of error
body: <p>I am trying to unit test a http async service.</p>
  
  <p>My Service:</p>
  
  <pre><code>@Injectable()
  export class MenuService {
    url = 'http://localhost:8080/rest/menu';
  
    constructor(private httpClient: HttpClient) {
    }
  
    async getMenus() {
      return this.httpClient.get&lt;MenuData[]&gt;(this.url).toPromise();
    }
  }
  </code></pre>
  
  <p>My test</p>
  
  <pre><code>describe('MenuService', () =&gt; {
    let service: MenuService;
    let httpMock: HttpTestingController;
  
    beforeEach(() =&gt; {
      TestBed.configureTestingModule({
        imports: [HttpClientTestingModule],
        providers: [MenuService],
      });
  
      service = TestBed.get(MenuService);
      httpMock = TestBed.get(HttpTestingController);
    });
  
    it('should get all menus', async () =&gt; {
  
      const menus = service.getMenus().then((data: MenuData[]) =&gt; {
        expect(data.length).toBe(2);
      });
  
      const req = httpMock.expectOne('http://localhost:8080/rest/menu', 'call to api');
      expect(req.request.method).toEqual('GET');
  
      req.flush([&lt;MenuData&gt;{id: 1, name: 'Test', discreteSubMenus: false, subMenus: false}]);
    });
  
    afterEach(() =&gt; {
      httpMock.verify();
    });
  });
  </code></pre>
  
  <p>Test results look the following </p>
  
  <p><a href="https://i.stack.imgur.com/eTNsY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eTNsY.png" alt="enter image description here"></a></p>
  
  <p>This is the test result if i change the <code>async getMenus()</code> to </p>
  
  <pre><code> getMenus(): Observable&lt;MenuData[]&gt; {
      return this.httpClient.get&lt;MenuData[]&gt;(this.url);
    }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/5VE4s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5VE4s.png" alt="enter image description here"></a></p>
  
  <p>Which looks more correct. Because the MenuService Test failed and not the whole test. How can I change my test code to correctly test the async method?</p>